diff --git a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java index 2fd16f8f8f..00b5b698af 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java @@ -240,6 +240,15 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont transactionCoordinator.invalidate(); } + protected void prepareForAutoClose() { + waitingForAutoClose = true; + closed = true; + // For non-shared transaction coordinators, we have to add the observer + if ( !isTransactionCoordinatorShared ) { + addSharedSessionTransactionObserver( transactionCoordinator ); + } + } + @Override public boolean shouldAutoJoinTransaction() { return autoJoinTransactions; diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java index 0a0396681f..a81bd3fc38 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java @@ -377,8 +377,7 @@ public class SessionImpl } else { //Otherwise, session auto-close will be enabled by shouldAutoCloseSession(). - waitingForAutoClose = true; - closed = true; + prepareForAutoClose(); } } else {