Skip to content

Commit ecd6f50

Browse files
dreab8sebersole
authored andcommitted
HHH-12540 - Reusing same EntityTransaction with JTA enabled
1 parent ca86633 commit ecd6f50

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ protected void addSharedSessionTransactionObserver(TransactionCoordinator transa
212212
}
213213

214214
protected void removeSharedSessionTransactionObserver(TransactionCoordinator transactionCoordinator) {
215+
transactionCoordinator.invalidate();
215216
}
216217

217218
@Override

hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2741,6 +2741,7 @@ public void afterCompletion(boolean successful, boolean delayed) {
27412741

27422742
@Override
27432743
protected void removeSharedSessionTransactionObserver(TransactionCoordinator transactionCoordinator) {
2744+
super.removeSharedSessionTransactionObserver( transactionCoordinator );
27442745
transactionCoordinator.removeObserver( transactionObserver );
27452746
}
27462747

hibernate-core/src/main/java/org/hibernate/resource/transaction/backend/jta/internal/JtaTransactionCoordinatorImpl.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ public JtaTransactionCoordinatorImpl(
118118
synchronizationRegistered = false;
119119

120120
pulse();
121-
122121
}
123122

124123
/**
@@ -337,6 +336,14 @@ public int getTimeOut() {
337336
return this.timeOut;
338337
}
339338

339+
@Override
340+
public void invalidate() {
341+
if ( physicalTransactionDelegate != null ) {
342+
physicalTransactionDelegate.invalidate();
343+
}
344+
physicalTransactionDelegate = null;
345+
}
346+
340347
// SynchronizationCallbackTarget ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
341348

342349
@Override
@@ -377,11 +384,6 @@ public void afterCompletion(boolean successful, boolean delayed) {
377384
observer.afterCompletion( successful, delayed );
378385
}
379386

380-
if ( physicalTransactionDelegate != null ) {
381-
physicalTransactionDelegate.invalidate();
382-
}
383-
384-
physicalTransactionDelegate = null;
385387
synchronizationRegistered = false;
386388
}
387389

@@ -394,7 +396,6 @@ public void removeObserver(TransactionObserver observer) {
394396
observers.remove( observer );
395397
}
396398

397-
398399
/**
399400
* Implementation of the LocalInflow for this TransactionCoordinator. Allows the
400401
* local transaction ({@link org.hibernate.Transaction} to callback into this

hibernate-core/src/main/java/org/hibernate/resource/transaction/spi/TransactionCoordinator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ default boolean isTransactionActive(boolean isMarkedRollbackConsideredActive) {
106106
return isJoined() && getTransactionDriverControl().isActive( isMarkedRollbackConsideredActive );
107107
}
108108

109+
default void invalidate(){}
110+
109111
/**
110112
* Provides the means for "local transactions" (as transaction drivers) to control the
111113
* underlying "physical transaction" currently associated with the TransactionCoordinator.

0 commit comments

Comments
 (0)