Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -461,37 +461,35 @@ public boolean isClosed() {

@Override
public void close() {
if ( closed && !waitingForAutoClose ) {
return;
}

try {
delayedAfterCompletion();
}
catch ( HibernateException e ) {
if ( getFactory().getSessionFactoryOptions().isJpaBootstrap() ) {
throw getExceptionConverter().convert( e );
if ( !closed || waitingForAutoClose ) {
try {
delayedAfterCompletion();
}
else {
throw e;
catch ( HibernateException e ) {
if ( getFactory().getSessionFactoryOptions().isJpaBootstrap() ) {
throw getExceptionConverter().convert( e );
}
else {
throw e;
}
}
}

if ( sessionEventsManager != null ) {
sessionEventsManager.end();
}
if ( sessionEventsManager != null ) {
sessionEventsManager.end();
}

if ( transactionCoordinator != null ) {
removeSharedSessionTransactionObserver( transactionCoordinator );
}
if ( transactionCoordinator != null ) {
removeSharedSessionTransactionObserver( transactionCoordinator );
}

try {
if ( shouldCloseJdbcCoordinatorOnClose( isTransactionCoordinatorShared ) ) {
jdbcCoordinator.close();
try {
if ( shouldCloseJdbcCoordinatorOnClose( isTransactionCoordinatorShared ) ) {
jdbcCoordinator.close();
}
}
finally {
setClosed();
}
}
finally {
setClosed();
}
}

Expand Down Expand Up @@ -553,10 +551,9 @@ public void markForRollbackOnly() {

@Override
public boolean isTransactionInProgress() {
if ( waitingForAutoClose ) {
return factory.isOpen() && transactionCoordinator.isTransactionActive();
}
return !isClosed() && transactionCoordinator.isTransactionActive();
return waitingForAutoClose
? factory.isOpen() && transactionCoordinator.isTransactionActive()
: !isClosed() && transactionCoordinator.isTransactionActive();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ private ClearEvent createClearEvent() {
public void close() throws HibernateException {
if ( isClosed() ) {
if ( getFactory().getSessionFactoryOptions().getJpaCompliance().isJpaClosedComplianceEnabled() ) {
throw new IllegalStateException( "Illegal call to #close() on already closed Session/EntityManager" );
throw new IllegalStateException( "EntityManager was already closed" );
}
log.trace( "Already closed" );
}
Expand Down Expand Up @@ -465,13 +465,10 @@ protected boolean shouldCloseJdbcCoordinatorOnClose(boolean isTransactionCoordin
if ( isTransactionCoordinatorShared ) {
final ActionQueue actionQueue = getActionQueue();
if ( actionQueue.hasBeforeTransactionActions() || actionQueue.hasAfterTransactionActions() ) {
log.warn( "On close, shared Session had before/after transaction actions that have not yet been processed" );
log.warn( "Closing shared session with unprocessed transaction completion actions" );
}
return false;
}
else {
return true;
}
return !isTransactionCoordinatorShared;
}

@Override
Expand All @@ -493,18 +490,19 @@ public boolean isOpen() {

protected void checkSessionFactoryOpen() {
if ( !getFactory().isOpen() ) {
log.debug( "Forcing Session/EntityManager closed as SessionFactory/EntityManagerFactory has been closed" );
log.debug( "Forcing-closing session since factory is already closed" );
setClosed();
}
}

private void managedFlush() {
if ( isClosed() && !waitingForAutoClose ) {
log.trace( "Skipping auto-flush due to session closed" );
return;
log.trace( "Skipping auto-flush since the session is closed" );
}
else {
log.trace( "Automatically flushing session" );
doFlush();
}
log.trace( "Automatically flushing session" );
doFlush();
}

@Override
Expand Down
Loading