In class org.hibernate.collection.spi.AbstractPersistentCollection<E> implements Serializable PersistentCollection<E> the method prepareForPossibleLoadingOutsideTransaction is called from unsetSession like following from class {{ org.hibernate.engine.internal}}.StatefulPersistenceContext:
 If you see in the screenshot, the {{currentSession}}holds a session object but this.session is null, which causes {{allowLoadOutsideTransaction}}to be set as false and throws exception later in {{prepareForPossibleLoadingOutsideTransaction}}becuase both sessiion and tempsession are null. I think currentsession variable should be passed to prepareForPossibleLoadingOutsideTransaction }}to check if a transaction is allowed outside transaction or not. {{allowLoadOutsideTransaction = session.getFactory().getSessionFactoryOptions().isInitializeLazyStateOutsideTransactionsEnabled(); |