StackOverflowError in 6.2 with @Proxy(lazy = false)

Hello,
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(BatchInitializeEntitySelectFetchInitializer.java:74)
at org.hibernate.sql.results.internal.InitializersList.resolveInstances(InitializersList.java:88)
at org.hibernate.sql.results.internal.StandardRowReader.coordinateInitializers(StandardRowReader.java:110)
at org.hibernate.sql.results.internal.StandardRowReader.readRow(StandardRowReader.java:87)
at org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:179)
at org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:33)
at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.doExecuteQuery(JdbcSelectExecutorStandardImpl.java:362)
at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.executeQuery(JdbcSelectExecutorStandardImpl.java:168)
at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.list(JdbcSelectExecutorStandardImpl.java:93)
at org.hibernate.sql.exec.spi.JdbcSelectExecutor.list(JdbcSelectExecutor.java:31)
at org.hibernate.loader.ast.internal.SingleIdEntityLoaderDynamicBatch.load(SingleIdEntityLoaderDynamicBatch.java:140)
at org.hibernate.loader.ast.internal.SingleIdEntityLoaderDynamicBatch.load(SingleIdEntityLoaderDynamicBatch.java:58)
at org.hibernate.persister.entity.AbstractEntityPersister.doLoad(AbstractEntityPersister.java:3367)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3357)
at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:602)
at org.hibernate.event.internal.DefaultLoadEventListener.loadFromCacheOrDatasource(DefaultLoadEventListener.java:588)
at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:557)
at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:550)
at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:202)
at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:241)
at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:106)
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:78)
at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:138)
at org.hibernate.internal.SessionImpl.fireLoadNoChecks(SessionImpl.java:1231)
at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1075)

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(https://hibernate.atlassian.net) with a test case(hibernate-test-case-templates/JPAUnitTestCase.java 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/JPAUnitTestCase.java 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