无法在JBPM中启动和完成任务

时间:2016-06-03 11:42:25

标签: java drools jbpm kie

我在KieWorkbench中创建了业务流程,并按如下方式构建了jar: 业务流程: 进程ID:myWorkflow.process

enter image description here

创建任务-Actor:myUser1

提交任务-Actor:myUser2

GAV: group:com.mycom.app.bpm

artifact:myWorkflow

版本:1.0

根据我的要求,我需要在一个模块(Test1.war)中创建任务([First Task]开始和完成)并在另一个模块(Test2.war)中提交任务[Second Task] start and complete) 。每个模块都有独立的UI。

Test1.war中的代码: RuntimeEngine创建过程:

String deploymentId = "com.sample:example:1.0";
ReleaseId releaseId = new ReleaseIdImpl("com.mycom.app.bpm",  "myWorkflow",  "1.0");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.domain");
RuntimeEnvironmentBuilder builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(releaseId).entityManagerFactory(emf).userGroupCallback(new CustomUserCallBack());
RuntimeEngine runtimeEngine = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(builder.get(), deploymentId).getRuntimeEngine(null);
KieSession ksession =runtimeEngine.getKieSession();
ProcessInstance processInstance = ksession.startProcess("myWorkflow.process", null);

TaskService taskService = runtimeEngine.getTaskService();
List<Status> status = new ArrayList<Status>();
status.add(Status.Ready);
status.add(Status.Reserved);

List<TaskSummary> tasks = taskService.getTasksByStatusByProcessInstanceId(processInstance.getId(), status, "en-UK");
taskService.start(tasks.get(0).getId(), "myUser1");
taskService.complete(tasks.get(0).getId(), "myUser1", null);

我在单独的表中保存了processIntanceId。

Test2.war中的代码 RuntimeEngine创建过程:

这里我正在检索processIntanceId并提交任务(业务流程中的第二个任务)

String deploymentId = "com.sample:example:1.0";
ReleaseId releaseId = new ReleaseIdImpl("com.mycom.app.bpm",  "myWorkflow",  "1.0");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.domain");
RuntimeEnvironmentBuilder builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(releaseId).entityManagerFactory(emf).userGroupCallback(new CustomUserCallBack());
RuntimeEngine runtimeEngine = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(builder.get(), deploymentId).getRuntimeEngine(null);
KieSession ksession =runtimeEngine.getKieSession();
TaskService taskService = runtimeEngine.getTaskService();

List<Status> status = new ArrayList<Status>();
status.add(Status.Ready);
status.add(Status.Reserved);

List<TaskSummary> tasks = taskService.getTasksByStatusByProcessInstanceId(processInstance.getId(), status, "en-UK");
taskService.start(tasks.get(0).getId(), "myUser2");
taskService.complete(tasks.get(0).getId(), "myUser2", null);

当我在第二个模块(Test2.war)中启动任务(提交)时,我得到以下异常:

  

[com.arjuna.ats.arjuna](ajp-localhost-127.0.0.1-8009-3)ARJUNA012125:   TwoPhaseCoordinator.beforeCompletion - 失败了   SynchronizationImple&LT; 0:ffff0a04302f:6c42330f:57515432:1cf9,   org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization@5cf07878

     
    

:javax.persistence.OptimisticLockException:org.hibernate.StaleObjectStateException:Row已被更新或删除     另一个事务(或unsaved-value映射不正确):     [org.drools.persistence.info.SessionInfo#11629] at     org.hibernate.ejb.AbstractEntityManagerImpl.wrapStaleStateException(AbstractEntityManagerImpl.java:1390)       在     org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1308)       在     org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1289)       在     org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1295)       在     org.hibernate.ejb.AbstractEntityManagerImpl $ CallbackExceptionMapperImpl.mapManagedFlushFailure(AbstractEntityManagerImpl.java:1481)       在     org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl.beforeCompletion(SynchronizationCallbackCoordinatorImpl.java:109)       在     org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization.beforeCompletion(RegisteredSynchronization.java:53)       在     com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:76)     [jbossjts-4.16.2.Final.jar:] at     com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:273)     [jbossjts-4.16.2.Final.jar:] at     com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:93)     [jbossjts-4.16.2.Final.jar:] at     com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:164)     [jbossjts-4.16.2.Final.jar:] at     com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1165)     [jbossjts-4.16.2.Final.jar:] at     com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:117)     [jbossjts-4.16.2.Final.jar:] at     com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75)     [jbossjts-integration-4.16.2.Final.jar:] at     org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:167)     [jboss-transaction-spi-7.0.0.Final.jar:7.0.0.Final] at     org.drools.persistence.jta.JtaTransactionManager.commit(JtaTransactionManager.java:226)     [drools-persistence-jpa-6.2.0.Final.jar:6.2.0.Final] at     org.jbpm.services.task.persistence.TaskTransactionInterceptor.execute(TaskTransactionInterceptor.java:56)     [jbpm-human-task-jpa-6.2.0.Final.jar:6.2.0.Final] at     org.drools.core.command.impl.AbstractInterceptor.executeNext(AbstractInterceptor.java:41)     [drools-core-6.2.0.Final.jar:6.2.0.Final] at     org.drools.persistence.jta.TransactionLockInterceptor.execute(TransactionLockInterceptor.java:79)     [drools-persistence-jpa-6.2.0.Final.jar:6.2.0.Final] at     org.jbpm.services.task.commands.TaskCommandExecutorImpl.execute(TaskCommandExecutorImpl.java:40)     [jbpm-human-task-core-6.2.0.Final.jar:6.2.0.Final] at     org.jbpm.services.task.impl.command.CommandBasedTaskService.complete(CommandBasedTaskService.java:156)     [jbpm-human-task-core-6.2.0.Final.jar:6.2.0.Final] at     org.jbpm.runtime.manager.impl.task.SynchronizedTaskService.complete(SynchronizedTaskService.java:130)     [jbpm-runtime-manager-6.2.0.Final.jar:6.2.0.Final]任何人都可以告诉     我在这做错了什么......

  

1 个答案:

答案 0 :(得分:1)

尝试切换到每个流程实例,而不是使用单例运行时管理器方法。并且还要确保在请求结束时将运行时引擎处理回runtimeManager。

原因是通过使用单例,您在两次战争中实例化同一会话的两个实例(相同的会话ID)(因为会话ID可以存储在jboss数据目录中,因此两个战争都会相同) 。