StackOverflowError when using createCriteriaInsertSelect with onConflict in Hibernate 6.5.3+ (including 7.0.0Beta)

Hello,

I’m encountering a severe issue when using the combination of createCriteriaInsertSelect and onConflict in Hibernate. In my project, when constructing an INSERT…SELECT query with onConflict enabled, I get a StackOverflowError during execution. The stack trace indicates that the error originates from an infinite recursive call (e.g., in methods such as SqmInsertSelectStatement.copy() and SqmConflictClause.copy()).

I have verified that this issue is reproducible on all versions from Hibernate 6.5.3.Final and above—including Hibernate 6.6.x and even Hibernate 7.0.0Beta.

A brief overview of my setup is as follows:

  • I’m using Spring Boot (with the Spring Boot BOM, e.g., spring-boot-dependencies:3.4.3), where the default hibernate-core version is 6.5.3.Final.
  • The query is constructed using the Criteria API (createCriteriaInsertSelect) and then onConflict() is called to handle duplicate key scenarios.

This seems to be a bug within Hibernate’s handling of these APIs, and I’m looking for any insights, workarounds, or updates regarding this behavior. Has anyone else encountered this issue or have a recommended solution? Any information regarding a fix in an upcoming release would be greatly appreciated.

Thank you for your assistance.

Hello @azihsoyn, thank you for reaching out with this topic. This definitely looks like a bug, so I would ask you to please try to create a reproducer with our test case template that demonstrates the stack overflow error and, if you are able to reproduce the issue, create a new ticket in our issue tracker and attach that reproducer.

Thank you for your prompt reply. I also appreciate your suggestion regarding the next steps. I will create a reproducer case and report back with further details.