HHH-13790 Temporary session not being closed

This commit is contained in:
Dmitriy Churilov 2024-12-06 11:05:31 +01:00 committed by Andrea Boriero
parent 27aff6eb01
commit 7780b74c21
1 changed files with 23 additions and 24 deletions

View File

@ -238,31 +238,30 @@ public abstract class AbstractPersistentCollection<E> implements Serializable, P
SharedSessionContractImplementor originalSession = null;
boolean isJTA = false;
if ( tempSession != null ) {
isTempSession = true;
originalSession = session;
session = tempSession;
isJTA = session.getTransactionCoordinator().getTransactionCoordinatorBuilder().isJta();
if ( !isJTA ) {
// Explicitly handle the transactions only if we're not in
// a JTA environment. A lazy loading temporary session can
// be created even if a current session and transaction are
// open (ex: session.clear() was used). We must prevent
// multiple transactions.
session.beginTransaction();
}
final CollectionPersister collectionDescriptor =
session.getSessionFactory()
.getMappingMetamodel()
.getCollectionDescriptor( getRole() );
session.getPersistenceContextInternal().addUninitializedDetachedCollection( collectionDescriptor, this );
}
try {
if ( tempSession != null ) {
isTempSession = true;
originalSession = session;
session = tempSession;
isJTA = session.getTransactionCoordinator().getTransactionCoordinatorBuilder().isJta();
if ( !isJTA ) {
// Explicitly handle the transactions only if we're not in
// a JTA environment. A lazy loading temporary session can
// be created even if a current session and transaction are
// open (ex: session.clear() was used). We must prevent
// multiple transactions.
session.beginTransaction();
}
final CollectionPersister collectionDescriptor =
session.getSessionFactory()
.getMappingMetamodel()
.getCollectionDescriptor( getRole() );
session.getPersistenceContextInternal()
.addUninitializedDetachedCollection( collectionDescriptor, this );
}
return lazyInitializationWork.doWork();
}
finally {