Skip to content
This repository was archived by the owner on Nov 15, 2022. It is now read-only.

Commit afe7c99

Browse files
Backporting to 4.1.2 - GLASSFISH-21172 javax.transaction.RollbackException from @transactional bean has no cause set
svn path=/branches/4.1.2/; revision=64504 Former-commit-id: 73e64a9d75566d399cd29a6c93089b77e9a89686
1 parent 39c5c6c commit afe7c99

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

appserver/web/weld-integration/src/main/java/org/glassfish/cdi/transaction/TransactionalInterceptorBase.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2012-2014 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -225,6 +225,7 @@ public Object proceed(InvocationContext ctx) throws Exception {
225225
try {
226226
object = ctx.proceed();
227227
} catch (RuntimeException runtimeException) {
228+
_logger.log(java.util.logging.Level.INFO, "Error during transaction processing", runtimeException);
228229
Class dontRollbackOnClass =
229230
getClassInArrayClosestToClassOrNull(dontRollbackOn, runtimeException.getClass());
230231
if (dontRollbackOnClass == null) { //proceed as default...
@@ -253,6 +254,7 @@ else if(dontRollbackOnClass.isAssignableFrom(rollbackOnClass)) {
253254
markRollbackIfActiveTransaction();
254255
throw runtimeException;
255256
} catch (Exception checkedException) {
257+
_logger.log(java.util.logging.Level.INFO, "Error during transaction processing", checkedException);
256258
Class rollbackOnClass =
257259
getClassInArrayClosestToClassOrNull(rollbackOn, checkedException.getClass());
258260
if (rollbackOnClass == null) { //proceed as default...

appserver/web/weld-integration/src/main/java/org/glassfish/cdi/transaction/TransactionalInterceptorRequired.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -45,6 +45,7 @@
4545
import javax.interceptor.AroundInvoke;
4646
import javax.interceptor.Interceptor;
4747
import javax.interceptor.InvocationContext;
48+
import javax.transaction.Status;
4849
import javax.transaction.TransactionalException;
4950
import java.util.logging.Logger;
5051

@@ -92,18 +93,24 @@ public Object transactional(InvocationContext ctx) throws Exception {
9293
try {
9394
proceed = proceed(ctx);
9495
} finally {
95-
if (isTransactionStarted)
96+
if (isTransactionStarted) {
9697
try {
97-
getTransactionManager().commit();
98+
// Exception handling for proceed method call above can set TM/TRX as setRollbackOnly
99+
if(getTransactionManager().getTransaction().getStatus() == Status.STATUS_MARKED_ROLLBACK) {
100+
getTransactionManager().rollback();
101+
} else {
102+
getTransactionManager().commit();
103+
}
98104
} catch (Exception exception) {
99105
String messageString =
100106
"Managed bean with Transactional annotation and TxType of REQUIRED " +
101107
"encountered exception during commit " +
102108
exception;
103109
_logger.log(java.util.logging.Level.INFO,
104-
CDI_JTA_MBREQUIREDCT, exception);
110+
CDI_JTA_MBREQUIREDCT, exception);
105111
throw new TransactionalException(messageString, exception);
106112
}
113+
}
107114
}
108115
return proceed;
109116
} finally {

appserver/web/weld-integration/src/main/java/org/glassfish/cdi/transaction/TransactionalInterceptorRequiresNew.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -45,6 +45,7 @@
4545
import javax.interceptor.AroundInvoke;
4646
import javax.interceptor.Interceptor;
4747
import javax.interceptor.InvocationContext;
48+
import javax.transaction.Status;
4849
import javax.transaction.Transaction;
4950
import javax.transaction.TransactionalException;
5051
import java.util.logging.Logger;
@@ -96,7 +97,12 @@ public Object transactional(InvocationContext ctx) throws Exception {
9697
proceed = proceed(ctx);
9798
} finally {
9899
try {
99-
getTransactionManager().commit();
100+
// Exception handling for proceed method call above can set TM/TRX as setRollbackOnly
101+
if(getTransactionManager().getTransaction().getStatus() == Status.STATUS_MARKED_ROLLBACK) {
102+
getTransactionManager().rollback();
103+
} else {
104+
getTransactionManager().commit();
105+
}
100106
} catch (Exception exception) {
101107
String messageString =
102108
"Managed bean with Transactional annotation and TxType of REQUIRES_NEW " +

0 commit comments

Comments
 (0)