Hibernate integration - fail to fetch eagerly collection with 5.6.7 hibernate version

Description

  1. Starting from version 16.1.1 using Hibernate version 5.6.7.Final dependent objects are not eagerly retrieved (FetchType.EAGER is not respected) using our Hibernate integration with default settings. This works with the same settings in Hibernate version 5.3.10.Final.

  2. Our default hibernate settings use Hibernate’s query.scroll(). There is a bug when query.scroll() is asked to eagerly fetch dependent objects. This has been reported to Hibernate.

  3. Trying to read objects with dependent objects may fail during InitialLoad with a LazyInitializationException, because we expected the object to be eagerly loaded but instead it used lazy initialization.

  4. Workaround 1: In the DefaultHibernateSpaceDataSourceFactoryBean, set useScrollableResultSet to false. Doing so will result in the use of our DefaultChunkListDataIterator class. Setting fetchSize can be used to set the ‘chunk' size. Default is 100. Hibernate’s query.setFirstResult(x).setFetchSize(y).list() will be used instead of query.setFirstResult(x).setFetchSize(y).scroll().

  5. Workaround 2: If limitResults is also set, the DefaultListQueryDataIterator will be used and contents of the database will be loaded into the list in one pass without ‘chunking/batching’. Our recommendation is to not set this so the DefaultChunkListDataIterator mentioned above will be used.

  6. Workaround 3: Set hibernate.enable_lazy_load_no_trans=true - in most scenarios dependent objects will be fetched when needed if the call to fetch is triggered for the first time by the same JVM that called the initial load.

  7. We aim to remove the integration from gs core in order to allow customers to upgrade hibernate when needed and have complete visibility, control, and responsibility over the integration.

Full exception:

SEVERE [com.gigaspaces.space.demo.1] - org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.mycompany.app.model.Team.players, could not initialize proxy - no Session; Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.mycompany.app.model.Team.players, could not initialize proxy - no Session [gsc][5/7275] at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:606) [gsc][5/7275] at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:218) [gsc][5/7275] at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:585) [gsc][5/7275] at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:149) [gsc][5/7275] at org.hibernate.collection.internal.PersistentSet.toString(PersistentSet.java:327) [gsc][5/7275] at com.gigaspaces.internal.document.DocumentObjectConverterInternal.toSpaceStringProperty(DocumentObjectConverterInternal.java:195) [gsc][5/7275] at com.gigaspaces.internal.document.DocumentObjectConverterInternal.convertNonPrimitiveFixedPropertiesToStrings(DocumentObjectConverterInternal.java:91) [gsc][5/7275] at com.gigaspaces.internal.document.DocumentObjectConverterInternal.convertNonPrimitivePropertiesToStrings(DocumentObjectConverterInternal.java:61) [gsc][5/7275] at com.gigaspaces.internal.server.space.SpaceImpl.applyEntryPacketOutFilter(SpaceImpl.java:2535) [gsc][5/7275] at com.gigaspaces.internal.server.space.SpaceImpl.readMultiple(SpaceImpl.java:2508) [gsc][5/7275] at com.gigaspaces.internal.server.space.operations.ReadTakeEntriesSpaceOperation.execute(ReadTakeEntriesSpaceOperation.java:41) [gsc][5/7275] at com.gigaspaces.internal.server.space.operations.ReadTakeEntriesSpaceOperation.execute(ReadTakeEntriesSpaceOperation.java:32) [gsc][5/7275] at com.gigaspaces.internal.server.space.operations.SpaceOperationsExecutor.executeOperation(SpaceOperationsExecutor.java:83) [gsc][5/7275] at com.gigaspaces.internal.server.space.SpaceImpl.executeOperation(SpaceImpl.java:2110) [gsc][5/7275] at com.gigaspaces.internal.lrmi.stubs.LRMISpaceImpl.executeOperation(LRMISpaceImpl.java:656) [gsc][5/7275] at com.gigaspaces.internal.remoting.routing.embedded.EmbeddedRemoteOperationRouter$AsyncOperationExecutor.execute(EmbeddedRemoteOperationRouter.java:179) [gsc][5/7275] at com.gigaspaces.internal.utils.concurrent.ContextClassLoaderRunnable.run(ContextClassLoaderRunnable.java:45) [gsc][5/7275] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [gsc][5/7275] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [gsc][5/7275] at java.lang.Thread.run(Thread.java:748)

 

Test available in Tgrid.

Activity

Details

Assignee

Reporter

Labels

Participants of an issue

Ester Atsmon

Priority

Edition

Platform

All

Freshdesk Support

Open Freshdesk Support
Created September 12, 2022 at 9:15 AM
Updated August 30, 2023 at 8:26 AM
Freshdesk Support