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.

1 Like

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.

@azihsoyn
The workaround is to turn the copy tree off in the application props: hibernate.criteria.copy_tree=false

1 Like

@Borys_Makhlin

Is there really such a method!?
I’ll give it a try right away!!

I was actually trying to add a test case as you advised, but I was stuck because I couldn’t reproduce the issue.
Thank you so much!

@azihsoyn it’s strange, I reproduced the issue yesterday createCriteriaInsertValues, createCriteriaInsertSelect, StackOverflowException

@Borys_Makhlin

Works fine!
Thank you for your help!

Please try to create a reproducer with our test case template and if you are able to reproduce the issue, create a bug ticket in our issue tracker and attach that reproducer.

I’ve reported an issue on the jira board with a reproducer: Jira

Thank you!

Sincerely,
Borys

1 Like