From 7a72adedfa79db3d1118b1cdb587e383ecaa9528 Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Tue, 20 Jun 2023 19:39:08 +1200 Subject: [PATCH 1/2] #3109 JtaTransactionManager - fix getCurrentTransaction() Fix for JtaTransactionManager to allow Wildfly (or other) to throw an Exception when TransactionSynchronizationRegistry.getResource() is called. --- .../server/transaction/JtaTransactionManager.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java index f4b15b77e1..90a54993cb 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java @@ -79,10 +79,15 @@ private UserTransaction getUserTransaction() { @Override public Object getCurrentTransaction() { TransactionSynchronizationRegistry syncRegistry = getSyncRegistry(); - SpiTransaction t = (SpiTransaction) syncRegistry.getResource(EBEAN_TXN_RESOURCE); - if (t != null) { - // we have already seen this transaction - return t; + try { + SpiTransaction t = (SpiTransaction) syncRegistry.getResource(EBEAN_TXN_RESOURCE); + if (t != null) { + // we have already seen this transaction + return t; + } + } catch (Exception e) { + // deem that there is no current transaction + return null; } // check current Ebean transaction From fa1f225e671a581f7274647dec954e55beba1e18 Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Tue, 20 Jun 2023 19:41:00 +1200 Subject: [PATCH 2/2] #3109 follow up - refactor rename internal methods --- .../server/transaction/JtaTransactionManager.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java index 90a54993cb..3f5ac01598 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java @@ -52,7 +52,7 @@ private DataSource dataSource() { return transactionManager.dataSource(); } - private TransactionSynchronizationRegistry getSyncRegistry() { + private TransactionSynchronizationRegistry registry() { try { InitialContext ctx = new InitialContext(); return (TransactionSynchronizationRegistry) ctx.lookup("java:comp/TransactionSynchronizationRegistry"); @@ -61,7 +61,7 @@ private TransactionSynchronizationRegistry getSyncRegistry() { } } - private UserTransaction getUserTransaction() { + private UserTransaction userTransaction() { try { InitialContext ctx = new InitialContext(); return (UserTransaction) ctx.lookup("java:comp/UserTransaction"); @@ -78,7 +78,7 @@ private UserTransaction getUserTransaction() { */ @Override public Object getCurrentTransaction() { - TransactionSynchronizationRegistry syncRegistry = getSyncRegistry(); + TransactionSynchronizationRegistry syncRegistry = registry(); try { SpiTransaction t = (SpiTransaction) syncRegistry.getResource(EBEAN_TXN_RESOURCE); if (t != null) { @@ -98,7 +98,7 @@ public Object getCurrentTransaction() { return currentEbeanTransaction; } - UserTransaction ut = getUserTransaction(); + UserTransaction ut = userTransaction(); if (ut == null) { // no current JTA transaction if (log.isLoggable(DEBUG)) {