diff --git a/hibernate-core/src/main/java/org/hibernate/engine/transaction/synchronization/internal/SynchronizationCallbackCoordinatorNonTrackingImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/transaction/synchronization/internal/SynchronizationCallbackCoordinatorNonTrackingImpl.java index 3e1d76707d..da485ccdfb 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/transaction/synchronization/internal/SynchronizationCallbackCoordinatorNonTrackingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/transaction/synchronization/internal/SynchronizationCallbackCoordinatorNonTrackingImpl.java @@ -63,6 +63,10 @@ public class SynchronizationCallbackCoordinatorNonTrackingImpl implements Synchr afterCompletionAction = STANDARD_AFTER_COMPLETION_ACTION; } + protected final TransactionCoordinator transactionCoordinator() { + return transactionCoordinator; + } + private TransactionContext transactionContext() { return transactionCoordinator.getTransactionContext(); } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/transaction/synchronization/internal/SynchronizationCallbackCoordinatorTrackingImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/transaction/synchronization/internal/SynchronizationCallbackCoordinatorTrackingImpl.java index 23d58503ad..2fd804b962 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/transaction/synchronization/internal/SynchronizationCallbackCoordinatorTrackingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/transaction/synchronization/internal/SynchronizationCallbackCoordinatorTrackingImpl.java @@ -78,6 +78,10 @@ public class SynchronizationCallbackCoordinatorTrackingImpl extends Synchronizat // check for it in SessionImpl. See HHH-7910. delayedCompletionHandlingStatus = status; + // no matter what we need to release the Connection. Not releasing + // the Connection here can lead to leaked Connections. + transactionCoordinator().getJdbcCoordinator().getLogicalConnection().close(); + log.rollbackFromBackgroundThread( status ); return; }