From ffe45ccdd6fd0fdde1f685fe4075a7a3f2295c01 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Wed, 3 Feb 2021 11:19:46 +0100 Subject: [PATCH] Register transaction coordinator as observer when session is waiting for auto close but coordinator is not shared --- .../internal/AbstractSharedSessionContract.java | 9 +++++++++ .../main/java/org/hibernate/internal/SessionImpl.java | 3 +-- 2 files changed, 10 insertions(+), 2 deletions(-) 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 {