JBoss Community

fireUntilHalt with customworkhandler

created by Hina Agarwal in jBPM - View the full discussion

If we use cutom workitem handler as mentioned below and fireUntilhalt to invoke rules in reactive mode. While debugging, I found that before completing first task(line in blue & bold), it fires the rule which is active. After running of rule, it get back to end of completeworkitem.It creates a problem an thrpw an exception mentioned below.

 

WorkItemHandler

public class MyHumanChangingValuesSimulatorWorkItemHandler implements WorkItemHandler {
    private static int counter = 1;
    private WorkItemManager workItemManager;
    private long workItemId;
    private Map<String, Object> results;
    private Emergency currentEmergency;
 
    public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
        this.workItemId = workItem.getId();
        this.workItemManager = workItemManager;
        currentEmergency = (Emergency) workItem.getParameter("emergency");
        currentEmergency.setRevision(currentEmergency.getRevision() + counter);
 
 
    }
 
    public void abortWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
 
    }
 
    public void completeWorkItem() {
        results = new HashMap<String, Object>();
        results.put("emergency", currentEmergency);
        workItemManager.completeWorkItem(workItemId, results);
 
    }
 
 
}
 
 
 

 

 

Exception:

0    13/09 15:13:39,598[Thread-6] ERROR hibernate.util.JDBCExceptionReporter.logExceptions - error requeueing a JdbcPooledConnection from datasource jdbc/testDS in state ACCESSIBLE wrapping xads1: url=jdbc:h2:mem:mydb user=root
Hibernate: update ProcessInstanceInfo set lastModificationDate=?, lastReadDate=?, processId=?, processInstanceByteArray=?, startDate=?, state=?, OPTLOCK=? where InstanceId=? and OPTLOCK=?
3    13/09 15:13:39,601[Thread-6] ERROR hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException - Unable to mark for rollback on PersistenceException: 
java.lang.IllegalStateException: no transaction started on this thread
          at bitronix.tm.BitronixTransactionManager.setRollbackOnly(BitronixTransactionManager.java:123)
          at org.hibernate.ejb.AbstractEntityManagerImpl.markAsRollback(AbstractEntityManagerImpl.java:421)
          at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:576)
          at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
          at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:202)
          at org.jbpm.persistence.JpaProcessPersistenceContext.findProcessInstanceInfo(JpaProcessPersistenceContext.java:26)
          at org.jbpm.persistence.processinstance.JPAProcessInstanceManager.getProcessInstance(JPAProcessInstanceManager.java:59)
          at org.jbpm.process.instance.ProcessRuntimeImpl.getProcessInstance(ProcessRuntimeImpl.java:190)
          at org.drools.common.AbstractWorkingMemory.getProcessInstance(AbstractWorkingMemory.java:1113)
          at org.drools.impl.StatefulKnowledgeSessionImpl.getProcessInstance(StatefulKnowledgeSessionImpl.java:283)
          at org.jbpm.persistence.processinstance.JPASignalManager.signalEvent(JPASignalManager.java:24)
          at org.jbpm.process.instance.ProcessRuntimeImpl$3.afterRuleFlowGroupDeactivated(ProcessRuntimeImpl.java:335)
          at org.drools.event.AgendaEventSupport.fireAfterRuleFlowGroupDeactivated(AgendaEventSupport.java:168)
          at org.drools.common.RuleFlowGroupImpl.setActive(RuleFlowGroupImpl.java:148)
          at org.drools.common.RuleFlowGroupImpl$DeactivateCallback.execute(RuleFlowGroupImpl.java:301)
          at org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:994)
          at org.drools.common.DefaultAgenda.fireUntilHalt(DefaultAgenda.java:1037)
          at org.drools.common.AbstractWorkingMemory.fireUntilHalt(AbstractWorkingMemory.java:777)
          at org.drools.common.AbstractWorkingMemory.fireUntilHalt(AbstractWorkingMemory.java:753)
          at org.drools.command.runtime.rule.FireUntilHaltCommand$1.run(FireUntilHaltCommand.java:50)
          at java.lang.Thread.run(Unknown Source)
Exception in thread "Thread-6" org.drools.RuntimeDroolsException: Unexpected exception executing action org.drools.common.RuleFlowGroupImpl$DeactivateCallback@556949
          at org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:996)
          at org.drools.common.DefaultAgenda.fireUntilHalt(DefaultAgenda.java:1037)
          at org.drools.common.AbstractWorkingMemory.fireUntilHalt(AbstractWorkingMemory.java:777)
          at org.drools.common.AbstractWorkingMemory.fireUntilHalt(AbstractWorkingMemory.java:753)
          at org.drools.command.runtime.rule.FireUntilHaltCommand$1.run(FireUntilHaltCommand.java:50)
          at java.lang.Thread.run(Unknown Source)
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot release connection
          at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
          at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:202)
          at org.jbpm.persistence.JpaProcessPersistenceContext.findProcessInstanceInfo(JpaProcessPersistenceContext.java:26)
          at org.jbpm.persistence.processinstance.JPAProcessInstanceManager.getProcessInstance(JPAProcessInstanceManager.java:59)
          at org.jbpm.process.instance.ProcessRuntimeImpl.getProcessInstance(ProcessRuntimeImpl.java:190)
          at org.drools.common.AbstractWorkingMemory.getProcessInstance(AbstractWorkingMemory.java:1113)
          at org.drools.impl.StatefulKnowledgeSessionImpl.getProcessInstance(StatefulKnowledgeSessionImpl.java:283)
          at org.jbpm.persistence.processinstance.JPASignalManager.signalEvent(JPASignalManager.java:24)
          at org.jbpm.process.instance.ProcessRuntimeImpl$3.afterRuleFlowGroupDeactivated(ProcessRuntimeImpl.java:335)
          at org.drools.event.AgendaEventSupport.fireAfterRuleFlowGroupDeactivated(AgendaEventSupport.java:168)
          at org.drools.common.RuleFlowGroupImpl.setActive(RuleFlowGroupImpl.java:148)
          at org.drools.common.RuleFlowGroupImpl$DeactivateCallback.execute(RuleFlowGroupImpl.java:301)
          at org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:994)
          ... 5 more
Hibernate: select processins0_.InstanceId as InstanceId1_0_, processins0_.lastModificationDate as lastModi2_1_0_, processins0_.lastReadDate as lastRead3_1_0_, processins0_.processId as processId1_0_, processins0_.processInstanceByteArray as processI5_1_0_, processins0_.startDate as startDate1_0_, processins0_.state as state1_0_, processins0_.OPTLOCK as OPTLOCK1_0_ from ProcessInstanceInfo processins0_ where processins0_.InstanceId=?
Caused by: org.hibernate.exception.GenericJDBCException: Cannot release connection
          at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
          at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
          at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
          at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
          at org.hibernate.jdbc.ConnectionManager.closeConnection(ConnectionManager.java:478)
          at org.hibernate.jdbc.ConnectionManager.aggressiveRelease(ConnectionManager.java:429)
          at org.hibernate.jdbc.ConnectionManager.afterStatement(ConnectionManager.java:304)
          at org.hibernate.jdbc.AbstractBatcher.closePreparedStatement(AbstractBatcher.java:572)
          at org.hibernate.jdbc.AbstractBatcher.closeStatement(AbstractBatcher.java:291)
          at org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:307)
          at org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:234)
          at org.hibernate.loader.Loader.doQuery(Loader.java:749)
          at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
          at org.hibernate.loader.Loader.loadEntity(Loader.java:1881)
          at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:71)
          at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:65)
          at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3072)
          at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:434)
          at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:415)
          at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:165)
          at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:223)
          at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:126)
          at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:905)
          at org.hibernate.impl.SessionImpl.get(SessionImpl.java:842)
          at org.hibernate.impl.SessionImpl.get(SessionImpl.java:835)
          at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:182)
          ... 16 more
Caused by: java.sql.SQLException: error requeueing a JdbcPooledConnection from datasource jdbc/testDS in state ACCESSIBLE wrapping xads1: url=jdbc:h2:mem:mydb user=root
          at bitronix.tm.resource.jdbc.JdbcPooledConnection.release(JdbcPooledConnection.java:148)
          at bitronix.tm.resource.jdbc.JdbcConnectionHandle.close(JdbcConnectionHandle.java:77)
          at org.hibernate.connection.DatasourceConnectionProvider.closeConnection(DatasourceConnectionProvider.java:97)
          at org.hibernate.jdbc.ConnectionManager.closeConnection(ConnectionManager.java:474)
          ... 37 more
Caused by: bitronix.tm.internal.BitronixSystemException: cannot close a resource when its XAResource is taking part in an unfinished global transaction
          at bitronix.tm.resource.common.TransactionContextHelper.requeue(TransactionContextHelper.java:117)
          at bitronix.tm.resource.jdbc.JdbcPooledConnection.release(JdbcPooledConnection.java:146)
          ... 40 more
 

 

Please suggest me can we use fireUntilHalt() with customhumantask handler. Why it always beahave differently?

Reply to this message by going to Community

Start a new discussion in jBPM at Community