HHH-7296 - NPE in JtaTransaction#markRollbackOnly

This commit is contained in:
Steve Ebersole 2012-05-02 22:26:17 -05:00
parent a2a55d8ab6
commit 6ca09342f8
1 changed files with 11 additions and 4 deletions

View File

@ -68,10 +68,7 @@ public class JtaTransaction extends AbstractTransactionImpl {
protected void doBegin() { protected void doBegin() {
LOG.debug( "begin" ); LOG.debug( "begin" );
userTransaction = jtaPlatform().retrieveUserTransaction(); userTransaction = locateUserTransaction();
if ( userTransaction == null ) {
throw new TransactionException( "Unable to locate JTA UserTransaction" );
}
try { try {
if ( userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION ) { if ( userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION ) {
@ -83,7 +80,14 @@ public class JtaTransaction extends AbstractTransactionImpl {
catch ( Exception e ) { catch ( Exception e ) {
throw new TransactionException( "JTA transaction begin failed", e ); throw new TransactionException( "JTA transaction begin failed", e );
} }
}
private UserTransaction locateUserTransaction() {
final UserTransaction userTransaction = jtaPlatform().retrieveUserTransaction();
if ( userTransaction == null ) {
throw new TransactionException( "Unable to locate JTA UserTransaction" );
}
return userTransaction;
} }
@Override @Override
@ -208,6 +212,9 @@ public class JtaTransaction extends AbstractTransactionImpl {
public void markRollbackOnly() { public void markRollbackOnly() {
LOG.trace( "Marking transaction for rollback only" ); LOG.trace( "Marking transaction for rollback only" );
try { try {
if ( userTransaction == null ) {
userTransaction = locateUserTransaction();
}
userTransaction.setRollbackOnly(); userTransaction.setRollbackOnly();
LOG.debug( "set JTA UserTransaction to rollback only" ); LOG.debug( "set JTA UserTransaction to rollback only" );
} }