Skip to content

Commit dc72c94

Browse files
flexo0beikov
authored andcommitted
HHH-13790 Temporary session not being closed
1 parent b474cba commit dc72c94

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

hibernate-core/src/main/java/org/hibernate/collection/spi/AbstractPersistentCollection.java

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)