Skip to content

Commit

Permalink
Ensure that suspended transaction is always resumed
Browse files Browse the repository at this point in the history
If an exception happen inside commit (like an SQLException), the afterEndTransaction Runnable would not run.
This caused the suspended Transaction to be never resumed, for e.g. a nested Transaction REQUIRES_NEW.
  • Loading branch information
Postremus committed Dec 12, 2020
1 parent 6da76b1 commit 4b8881c
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,17 +301,19 @@ protected void handleException(InvocationContext ic, Exception e, Transaction tx

protected void endTransaction(TransactionManager tm, Transaction tx, RunnableWithException afterEndTransaction)
throws Exception {
if (tx != tm.getTransaction()) {
throw new RuntimeException(jtaLogger.i18NLogger.get_wrong_tx_on_thread());
}
try {
if (tx != tm.getTransaction()) {
throw new RuntimeException(jtaLogger.i18NLogger.get_wrong_tx_on_thread());
}

if (tx.getStatus() == Status.STATUS_MARKED_ROLLBACK) {
tm.rollback();
} else {
tm.commit();
if (tx.getStatus() == Status.STATUS_MARKED_ROLLBACK) {
tm.rollback();
} else {
tm.commit();
}
} finally {
afterEndTransaction.run();
}

afterEndTransaction.run();
}

protected boolean setUserTransactionAvailable(boolean available) {
Expand Down

0 comments on commit 4b8881c

Please sign in to comment.