Allow initialization of collections in a StatelessSession while scrolling/streaming results

Description

Currently, it's not possible to load a collection from a stateless session unless it is join-fetched in a query.

An attempt to initialize a collection without being join-fetched results in:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 org.hibernate.SessionException: collections cannot be fetched by a stateless session at org.hibernate.internal.StatelessSessionImpl.initializeCollection(StatelessSessionImpl.java:260) at org.hibernate.collection.internal.AbstractPersistentCollection$4.doWork(AbstractPersistentCollection.java:585) at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:263) at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:581) at org.hibernate.collection.internal.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:773) at org.hibernate.engine.internal.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:953) at org.hibernate.loader.Loader.loadSingleRow(Loader.java:404) at org.hibernate.internal.ScrollableResultsImpl.prepareCurrentRow(ScrollableResultsImpl.java:192) at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:100) at org.hibernate.test.stateless.scroll.StatelessNonFetchingScrollTest.lambda$testScrollInStatelessSession$1(StatelessNonFetchingScrollTest.java:68) at org.hibernate.testing.transaction.TransactionUtil2.inStatelessTransaction(TransactionUtil2.java:211) at org.hibernate.testing.transaction.TransactionUtil2.lambda$inStatelessTransaction$2(TransactionUtil2.java:199) at org.hibernate.testing.transaction.TransactionUtil2.inStatelessSession(TransactionUtil2.java:185) at org.hibernate.testing.transaction.TransactionUtil2.inStatelessTransaction(TransactionUtil2.java:197) at org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase.inStatelessTransaction(BaseNonConfigCoreFunctionalTestCase.java:577) at org.hibernate.test.stateless.scroll.StatelessNonFetchingScrollTest.testScrollInStatelessSession(StatelessNonFetchingScrollTest.java:62) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.hibernate.testing.junit4.ExtendedFrameworkMethod.invokeExplosively(ExtendedFrameworkMethod.java:45) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:298) at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:292) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.lang.Thread.run(Thread.java:748)

Documentation incorrectly says: "Collections are ignored by a stateless session".

Environment

None

Status

Assignee

Unassigned

Reporter

Gail Badner

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Priority

Major