Why does the custom WorkItemHandler throw "No active JTA transaction on joinTransaction call" exception while completing the WorkItem ?
Issue
- As per requirement there is a custom
WorkItemHandler
implementation which gets called during the execution of aBPMN2
process for aUser Task
. TheexecuteWorkItem()
method of the customWorkItemHandler
needs to do some lengthy operation (like, aWeb Service
invocation which takes longer time than usual to complete), so a separate thread has been introduced into theexecuteWorkItem()
method of the customWorkItemHandler
to do the lengthyWeb Service
invocation and return from theWorkItemHandler
before the task is finished.
As per plan after calling theWorkItemManager.completeWorkItem(workItemId, mappedData)
when the computation is finished on that thread , the call throw aTransactionRequiredException
statingNo 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.