### Eclipse Workspace Patch 1.0 #P jbpm4 Index: modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java =================================================================== --- modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java (revision 6421) +++ modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java (working copy) @@ -367,7 +367,7 @@ if (parent!=null) { - parent.removeExecution(this); + if (dbSession!=null) { // make sure task attached to this execution are completed or skipped @@ -378,6 +378,7 @@ dbSession.delete(this); } + parent.removeExecution(this); } else { // this is a process instance Index: modules/test-db/src/test/java/org/jbpm/test/activity/foreach/ForEachTest.java =================================================================== --- modules/test-db/src/test/java/org/jbpm/test/activity/foreach/ForEachTest.java (revision 6421) +++ modules/test-db/src/test/java/org/jbpm/test/activity/foreach/ForEachTest.java (working copy) @@ -435,4 +435,61 @@ assertEquals(1, historyTasks.size()); assertEquals(HistoryTask.STATE_OBSOLETE, historyTasks.get(0).getState()); } -} + + public void testForEachJoinMultiplicityLeftTasks() { + deployJpdlXmlString("" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""); + + Map variables = Collections.singletonMap("actors", Arrays.asList("alex", "mike", "bob")); + ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForEachJoinMultiplicity", variables); + + Task taskAlex = taskService.createTaskQuery().assignee("alex").uniqueResult(); + assertEquals("task1", taskAlex.getActivityName()); + taskService.completeTask(taskAlex.getId()); + + Task taskMike = taskService.createTaskQuery().assignee("mike").uniqueResult(); + assertNull(taskMike); + + Task taskBob = taskService.createTaskQuery().assignee("bob").uniqueResult(); + assertNull(taskBob); + + processInstance = executionService.findProcessInstanceById(processInstance.getId()); + + executionService.signalExecutionById(processInstance.getId()); + + HistoryProcessInstance history = historyService.createHistoryProcessInstanceQuery() + .processInstanceId(processInstance.getId()) + .uniqueResult(); + assertEquals(ProcessInstance.STATE_ENDED, history.getState()); + assertEquals("end1", history.getEndActivityName()); + + List historyTasks = historyService.createHistoryTaskQuery().assignee("alex").list(); + assertEquals(1, historyTasks.size()); + assertEquals(HistoryTask.STATE_COMPLETED, historyTasks.get(0).getState()); + + historyTasks = historyService.createHistoryTaskQuery().assignee("mike").list(); + assertEquals(1, historyTasks.size()); + assertEquals(HistoryTask.STATE_OBSOLETE, historyTasks.get(0).getState()); + + historyTasks = historyService.createHistoryTaskQuery().assignee("bob").list(); + assertEquals(1, historyTasks.size()); + assertEquals(HistoryTask.STATE_OBSOLETE, historyTasks.get(0).getState()); + } +} \ No newline at end of file