0 Replies Latest reply on Aug 23, 2010 10:49 AM by smalbequi

    Unable to delete process instances which have the same business key

    smalbequi

      Hi,

       

      The problem happens when you try to delete a second process wich has the same business key as a fisrt terminated process.

       

      Stéphane

       

      <process name="DeleteProcessTest" xmlns="http://jbpm.org/4.4/jpdl">
         <start name="start1" g="24,36,48,48">
            <transition to="task1"/>
         </start>
         <task name="task1" g="120,36,92,52">
            <transition to="end1"/>
         </task>
         <end name="end1" g="264,36,48,48"/>
      </process>

       

       

      public class DeleteProcessInstanceTest extends JbpmTestCase {
          private String deploymentId;

       

          @Override
          protected void setUp() throws Exception {
              super.setUp();
              deploymentId = repositoryService.createDeployment().addResourceFromClasspath("DeleteProcessTest.jpdl.xml").deploy();
          }

       

          @Override
          protected void tearDown() throws Exception {
              repositoryService.deleteDeploymentCascade(deploymentId);
              super.tearDown();

          }

       

          public void testDeleteProcess() throws Exception {
              // Start the first process
              ProcessInstance processInstance = executionService.startProcessInstanceByKey("DeleteProcessTest", "Key");
              Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).uniqueResult();
              taskService.completeTask(task.getId());     

              // First process is terminated
              Assert.assertNull(executionService.findExecutionById(processInstance.getId()));

       

              // Start second process
              processInstance = executionService.startProcessInstanceByKey("DeleteProcessTest", "Key");

       

              // Try to delete
              executionService.deleteProcessInstanceCascade(processInstance.getId());
          }
      }

       

       

      16:09:02,781 INFO  [DefaultCommandService] exception while executing command org.jbpm.pvm.internal.cmd.DeleteProcessInstance@30f82c
      org.hibernate.NonUniqueResultException: query did not return a unique result: 4
              at org.hibernate.impl.AbstractQueryImpl.uniqueElement(AbstractQueryImpl.java:820)
              at org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:305)
              at org.jbpm.pvm.internal.hibernate.DbSessionImpl.findHistoryProcessInstanceById(DbSessionImpl.java:231)
              at org.jbpm.pvm.internal.hibernate.DbSessionImpl.deleteProcessInstance(DbSessionImpl.java:174)