StackOverflowError in 6.2 with @Proxy(lazy = false)

I’m migration an application from 5.5.8 to 6.2.1 and I’m running into a StackOverflowError when loading objects using @Inheritance(strategy = InheritanceType.SINGLE_TABLE) and @Proxy(lazy = false)

Proxies were disabled on these classes to get around the issue that sometimes an instance was a proxy and an instanceof test wasn’t working as expected.
The entities have several levels of inheritance and are connected to each other with associations.

This was all fine but when upgrading to Hibernate 6 it seems like the behavior for loading associations (with at the same time proxies disabled) has changed.

The stacktrace looks like this (repeated multiple times):

at org.hibernate.sql.results.graph.entity.internal.BatchInitializeEntitySelectFetchInitializer.resolveInstance(
at org.hibernate.sql.results.internal.InitializersList.resolveInstances(
at org.hibernate.sql.results.internal.StandardRowReader.coordinateInitializers(
at org.hibernate.sql.results.internal.StandardRowReader.readRow(
at org.hibernate.sql.results.spi.ListResultsConsumer.consume(
at org.hibernate.sql.results.spi.ListResultsConsumer.consume(
at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.doExecuteQuery(
at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.executeQuery(
at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.list(
at org.hibernate.sql.exec.spi.JdbcSelectExecutor.list(
at org.hibernate.loader.ast.internal.SingleIdEntityLoaderDynamicBatch.load(
at org.hibernate.loader.ast.internal.SingleIdEntityLoaderDynamicBatch.load(
at org.hibernate.persister.entity.AbstractEntityPersister.doLoad(
at org.hibernate.persister.entity.AbstractEntityPersister.load(
at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(
at org.hibernate.event.internal.DefaultLoadEventListener.loadFromCacheOrDatasource(
at org.hibernate.event.internal.DefaultLoadEventListener.load(
at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(
at org.hibernate.event.internal.DefaultLoadEventListener.load(
at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(
at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(
at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(
at org.hibernate.internal.SessionImpl.fireLoadNoChecks(
at org.hibernate.internal.SessionImpl.internalLoad(

Can you please advise if that’s expected to happen (and we should stop disabling proxies) or if that might be a bug?
I’ve seen that the Proxy annotation was deprecated in 6.2 but it doesn’t elaborate on the reasons (or replacement).

Please create an issue in the issue tracker( with a test case(hibernate-test-case-templates/ at main · hibernate/hibernate-test-case-templates · GitHub) that reproduces the issue.

1 Like

Thanks for the answer Christian!
I’ll try to put together a test case reproducing the issue

I’ve created an issue here: [HHH-16553] - Hibernate JIRA
And a pull request here: HHH-16553 Test reproducing a stackoverflow when loading chained entities by gtoison · Pull Request #6507 · hibernate/hibernate-orm · GitHub

Christian, side question: the test case template you linked seems to be an older version of the tests and I’ve used JUnit5/@SessionFactory
Wouldn’t it make sense to update that template to the (better and newer!) version?

I posted the wrong link. There is a Hibernate 6 variant: hibernate-test-case-templates/ at main · hibernate/hibernate-test-case-templates · GitHub

Though you are right that it still uses JUnit 4. If you feel like it, you can provide a PR for upgrading the template to JUnit 5 :wink:

1 Like

Thanks Christian, when you have time to have a look at the failing test case I’ve submitted, could you please let me know if you feel that it’s a genuine issue in Hibernate or if I’m misusing it?

1 Like