improve some exception and log messages

This commit is contained in:
Gavin King 2024-12-16 10:15:01 +01:00
parent bd2be3f38f
commit 05cf85b61a
1 changed files with 9 additions and 11 deletions

View File

@ -397,7 +397,7 @@ public class SessionImpl
public void close() throws HibernateException { public void close() throws HibernateException {
if ( isClosed() ) { if ( isClosed() ) {
if ( getFactory().getSessionFactoryOptions().getJpaCompliance().isJpaClosedComplianceEnabled() ) { 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" ); log.trace( "Already closed" );
} }
@ -465,13 +465,10 @@ public class SessionImpl
if ( isTransactionCoordinatorShared ) { if ( isTransactionCoordinatorShared ) {
final ActionQueue actionQueue = getActionQueue(); final ActionQueue actionQueue = getActionQueue();
if ( actionQueue.hasBeforeTransactionActions() || actionQueue.hasAfterTransactionActions() ) { 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 @Override
@ -493,18 +490,19 @@ public class SessionImpl
protected void checkSessionFactoryOpen() { protected void checkSessionFactoryOpen() {
if ( !getFactory().isOpen() ) { 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(); setClosed();
} }
} }
private void managedFlush() { private void managedFlush() {
if ( isClosed() && !waitingForAutoClose ) { if ( isClosed() && !waitingForAutoClose ) {
log.trace( "Skipping auto-flush due to session closed" ); log.trace( "Skipping auto-flush since the session is closed" );
return; }
else {
log.trace( "Automatically flushing session" );
doFlush();
} }
log.trace( "Automatically flushing session" );
doFlush();
} }
@Override @Override