1 Reply Latest reply on Nov 5, 2012 5:41 AM by swiderski.maciej

    Exception when  use ksession.abortProcessInstance(processId) with LocalTaskService without persisted process instance

    ted.pan

      hi,

       

      When I use LocalTaskService without persisting process instance,  an exception will be thrown out when I use ksession.abortProcessInstance(processId);

      (I use jbpm 5.4.0.CR1)

       

      15:41:56,147 ERROR [com.mmm.sable.common.exceptionhandler.ErrorRedirectJSFPageHandler] (http--0.0.0.0-8080-2) 20121102071156147-816781937-- an error occurred : : javax.persistence.NonUniqueResultException: result returns more than one elements

          at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:298) [hibernate-entitymanager-4.1.7.Final.jar:4.1.7.Final]

          at org.jbpm.task.service.persistence.TaskPersistenceManager.queryWithParameters(TaskPersistenceManager.java:350) [jbpm-human-task-core-5.4.0.CR1.jar:5.4.0.CR1]

          at org.jbpm.task.service.persistence.TaskPersistenceManager.queryWithParametersInTransaction(TaskPersistenceManager.java:295) [jbpm-human-task-core-5.4.0.CR1.jar:5.4.0.CR1]

          at org.jbpm.task.service.TaskServiceSession.getTaskByWorkItemId(TaskServiceSession.java:752) [jbpm-human-task-core-5.4.0.CR1.jar:5.4.0.CR1]

          at org.jbpm.task.service.local.LocalTaskService.getTaskByWorkItemId(LocalTaskService.java:161) [jbpm-human-task-core-5.4.0.CR1.jar:5.4.0.CR1]

          at org.jbpm.process.workitem.wsht.GenericHTWorkItemHandler.abortWorkItem(GenericHTWorkItemHandler.java:203) [jbpm-human-task-core-5.4.0.CR1.jar:5.4.0.CR1]

          at org.drools.process.instance.impl.DefaultWorkItemManager.internalAbortWorkItem(DefaultWorkItemManager.java:89) [drools-core-5.5.0.CR1.jar:5.5.0.CR1]

          at org.jbpm.workflow.instance.node.WorkItemNodeInstance.cancel(WorkItemNodeInstance.java:257) [jbpm-flow-5.4.0.CR1.jar:5.4.0.CR1]

       

       

       

       

      By comparing the DefaultWorkItemManager with JPAWorkItemManager, there are different logic to set the workitemid in task table.

      in DefaultWorkItemManager,

                 ((WorkItemImpl) workItem).setId(workItemCounter.incrementAndGet());

       

      the workitem's id will begin with 1 every time restart. but JPAWorkItemManager will use WorkItemInfo's ID, which will be unique for each workitem.

                 WorkItemInfo workItemInfo = new WorkItemInfo(workItem, env);

             

              PersistenceContext context = ((PersistenceContextManager) env.get( EnvironmentName.PERSISTENCE_CONTEXT_MANAGER )).getCommandScopedPersistenceContext();

              context.persist( workItemInfo );

       

              ((WorkItemImpl) workItem).setId(workItemInfo.getId());

       

       

      So the result is:

      When try to cancel the process instance, because the workitem's id is always beginning with 1. there are many records in task table with workitemid = 1. then the exception(result returns more than one elements) happens.

       

      is this by design, or is a bug?

       

       

      Thanks