@@ -238,31 +238,30 @@ else if ( !session.isConnected() ) {
238238
239239 SharedSessionContractImplementor originalSession = null ;
240240 boolean isJTA = false ;
241+ try {
242+ if ( tempSession != null ) {
243+ isTempSession = true ;
244+ originalSession = session ;
245+ session = tempSession ;
246+
247+ isJTA = session .getTransactionCoordinator ().getTransactionCoordinatorBuilder ().isJta ();
248+
249+ if ( !isJTA ) {
250+ // Explicitly handle the transactions only if we're not in
251+ // a JTA environment. A lazy loading temporary session can
252+ // be created even if a current session and transaction are
253+ // open (ex: session.clear() was used). We must prevent
254+ // multiple transactions.
255+ session .beginTransaction ();
256+ }
241257
242- if ( tempSession != null ) {
243- isTempSession = true ;
244- originalSession = session ;
245- session = tempSession ;
246-
247- isJTA = session .getTransactionCoordinator ().getTransactionCoordinatorBuilder ().isJta ();
248-
249- if ( !isJTA ) {
250- // Explicitly handle the transactions only if we're not in
251- // a JTA environment. A lazy loading temporary session can
252- // be created even if a current session and transaction are
253- // open (ex: session.clear() was used). We must prevent
254- // multiple transactions.
255- session .beginTransaction ();
258+ final CollectionPersister collectionDescriptor =
259+ session .getSessionFactory ()
260+ .getMappingMetamodel ()
261+ .getCollectionDescriptor ( getRole () );
262+ session .getPersistenceContextInternal ()
263+ .addUninitializedDetachedCollection ( collectionDescriptor , this );
256264 }
257-
258- final CollectionPersister collectionDescriptor =
259- session .getSessionFactory ()
260- .getMappingMetamodel ()
261- .getCollectionDescriptor ( getRole () );
262- session .getPersistenceContextInternal ().addUninitializedDetachedCollection ( collectionDescriptor , this );
263- }
264-
265- try {
266265 return lazyInitializationWork .doWork ();
267266 }
268267 finally {
0 commit comments