HHH-4808 SessionImpl.initializeCollection() does not release JDBC connection (if outside of a transaction)
This commit is contained in:
parent
179c1d1da0
commit
3ea0484122
|
@ -251,7 +251,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
// be created even if a current session and transaction are
|
||||
// open (ex: session.clear() was used). We must prevent
|
||||
// multiple transactions.
|
||||
( (Session) session ).beginTransaction();
|
||||
session.beginTransaction();
|
||||
}
|
||||
|
||||
session.getPersistenceContextInternal().addUninitializedDetachedCollection(
|
||||
|
@ -265,20 +265,26 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
|
|||
}
|
||||
finally {
|
||||
if ( tempSession != null ) {
|
||||
|
||||
// make sure the just opened temp session gets closed!
|
||||
isTempSession = false;
|
||||
session = originalSession;
|
||||
|
||||
try {
|
||||
if ( !isJTA ) {
|
||||
( (Session) tempSession ).getTransaction().commit();
|
||||
tempSession.getTransaction().commit();
|
||||
}
|
||||
( (Session) tempSession ).close();
|
||||
tempSession.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.warn( "Unable to close temporary session used to load lazy collection associated to no session" );
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ( !session.isTransactionInProgress() ) {
|
||||
session.getJdbcCoordinator().afterTransaction();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -163,6 +163,7 @@ public abstract class AbstractLazyInitializer implements LazyInitializer {
|
|||
@Override
|
||||
public final void initialize() throws HibernateException {
|
||||
if ( !initialized ) {
|
||||
try {
|
||||
if ( allowLoadOutsideTransaction ) {
|
||||
permissiveInitialization();
|
||||
}
|
||||
|
@ -181,6 +182,12 @@ public abstract class AbstractLazyInitializer implements LazyInitializer {
|
|||
checkTargetState( session );
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if ( session != null && !session.isTransactionInProgress() ) {
|
||||
session.getJdbcCoordinator().afterTransaction();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
checkTargetState(session);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue