Why does the custom WorkItemHandler throw "No active JTA transaction on joinTransaction call" exception while completing the WorkItem ?

Solution Unverified - Updated -

Issue

  • As per requirement there is a custom WorkItemHandler implementation which gets called during the execution of a BPMN2 process for a User Task. The executeWorkItem() method of the custom WorkItemHandler needs to do some lengthy operation (like, a Web Service invocation which takes longer time than usual to complete), so a separate thread has been introduced into the executeWorkItem() method of the custom WorkItemHandler to do the lengthy Web Service invocation and return from the WorkItemHandler before the task is finished.
    As per plan after calling the WorkItemManager.completeWorkItem(workItemId, mappedData) when the computation is finished on that thread , the call throw a TransactionRequiredException stating No active JTA transaction o joinTransaction call.
WARN [org.hibernate.ejb.AbstractEntityManagerImpl] (Thread-115) HHH000326: Cannot join transaction: do not override hibernate.transaction.factory_class 
SEVERE [com.sample.test.jbpm.workitemhandlers.CustomWSHandler] (Thread-115) Unable to complete the work item: javax.persistence.TransactionRequiredException: No active JTA transaction on joinTransaction call 
     at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:1233) [hibernate-entitymanager-4.2.0.Final-redhat-1.jar:4.2.0.Final-redhat-1] 
     at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:1183) [hibernate-entitymanager-4.2.0.Final-redhat-1.jar:4.2.0.Final-redhat-1] 
     at org.drools.persistence.jpa.JpaPersistenceContextManager.beginCommandScopedEntityManager(JpaPersistenceContextManager.java:83) [drools-persistence-jpa-5.3.1.BRMS.jar:5.3.1.BRMS] 
     at org.jbpm.persistence.processinstance.JPAProcessInstanceManager.getProcessInstance(JPAProcessInstanceManager.java:75) [jbpm-persistence-jpa-5.3.1.BRMS.jar:5.3.1.BRMS] 
     at org.jbpm.process.instance.ProcessRuntimeImpl.getProcessInstance(ProcessRuntimeImpl.java:205) [jbpm-flow-5.3.1.BRMS.jar:5.3.1.BRMS] 
     at org.drools.common.AbstractWorkingMemory.getProcessInstance(AbstractWorkingMemory.java:1100) [drools-core-5.3.1.BRMS.jar:5.3.1.BRMS] 
     at org.drools.impl.StatefulKnowledgeSessionImpl.getProcessInstance(StatefulKnowledgeSessionImpl.java:295) [drools-core-5.3.1.BRMS.jar:5.3.1.BRMS] 
     at org.drools.persistence.jpa.processinstance.JPAWorkItemManager.completeWorkItem(JPAWorkItemManager.java:117) [drools-persistence-jpa-5.3.1.BRMS.jar:5.3.1.BRMS] 
     at com.sample.test.jbpm.workitemhandlers.CustomWSHandler.completeWorkItem(WebServiceHandler.java:154) [classes:] 
...

The sample code for the custom WorkItemHandler is quoted below.

public class CustomWSHandler extends WorkItemHandler
{

   @Override
   public void executeWorkitem(WorkItem wItem, WorkItemManager wItemManager)
   {

       new Thread(new Runnable()
       {
          WorkItem         wItem;
          WorkItemManager  wItemManager; 

          public void run() {
             //Make Web Service call here          
             workItemManager.completeWorkItem(wItem.getId(), mappedData);
          };

          protected Runnable init(WorkItem workItem, WorkitemManager workItemManager)
          {
             this.wItem = workItem;
             this.wItemManager = workItemManager;
             return this;
           }
       }).init(wItemManager, wItem).start();
   }

How to fix this issue?

Environment

  • Red Hat JBoss BRMS (BRMS)
    • 5.3.x

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content