diff --git a/hibernate-core/src/main/java/org/hibernate/collection/spi/AbstractPersistentCollection.java b/hibernate-core/src/main/java/org/hibernate/collection/spi/AbstractPersistentCollection.java index 1b243e2095..ff2dd2b778 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/spi/AbstractPersistentCollection.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/spi/AbstractPersistentCollection.java @@ -238,31 +238,30 @@ public abstract class AbstractPersistentCollection 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 {