Skip to content

Commit

Permalink
[JBPM-9184] Subprocess excepcion handling tx rollback causes main pro…
Browse files Browse the repository at this point in the history
…cess to fail

The error happens when a subprocess is invoked sync and therefore is not the owner of the tx.
In this case we need to let the main process handle the rollback
  • Loading branch information
Enrique Gonzalez Martinez authored and elguardian committed Jul 31, 2020
1 parent 74c1096 commit e2cc4a2
Showing 1 changed file with 18 additions and 7 deletions.
Expand Up @@ -63,6 +63,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.lang.Boolean.TRUE;
import static org.drools.persistence.api.TransactionManager.STATUS_ACTIVE;

public class PersistableRunner implements SingleSessionCommandService {

private static Logger logger = LoggerFactory.getLogger( PersistableRunner.class );
Expand Down Expand Up @@ -578,11 +581,18 @@ public RequestContext execute( Executable executable, RequestContext context ) {

// Open the entity manager before the transaction begins.
PersistenceContext persistenceContext = jpm.getApplicationScopedPersistenceContext();

// We flag the current persistence runner
final String DROOLS_PARENT_RUNNER = "DROOLS_PARENT_RUNNER";
boolean isParentRunner = txm.getResource(DROOLS_PARENT_RUNNER) == null;
boolean transactionOwner = false;

try {
if (isParentRunner && txm.getStatus() == STATUS_ACTIVE) {
txm.putResource(DROOLS_PARENT_RUNNER, TRUE);
}
transactionOwner = txm.begin();


persistenceContext.joinTransaction();

initExistingKnowledgeSession( sessionInfo.getId(),
Expand All @@ -600,14 +610,15 @@ public RequestContext execute( Executable executable, RequestContext context ) {
txm.commit( transactionOwner );

} catch ( RuntimeException re ) {
rollbackTransaction( re,
transactionOwner );
if (isParentRunner) {
rollbackTransaction(re, transactionOwner);
}
throw re;
} catch ( Exception t1 ) {
rollbackTransaction( t1,
transactionOwner );
throw new RuntimeException( "Wrapped exception see cause",
t1 );
if (isParentRunner) {
rollbackTransaction(t1, transactionOwner);
}
throw new RuntimeException("Wrapped exception see cause", t1);
}

return context;
Expand Down

0 comments on commit e2cc4a2

Please sign in to comment.