13 Replies Latest reply on Jul 10, 2009 10:58 AM by shekharv

    JBPM4: FOREIGN KEY problem

      hi.
      A question block me, Please help me .thank you very much.
      I download jbpm-4.0.CR1. Import jbpm.mysql.create.sql contents to MySql 5.

      I create Order and TestUpdate , When I run TestUpdate , some exception print in cnosole. It seems question is FOREIGN KEY problem.
      Please tell me how to fix it. Thank you very much.

      Below are source code, and exceptin message.



      package taskassign;

      import java.io.Serializable;

      public class Order implements Serializable {

      /**
      *
      */
      private static final long serialVersionUID = 7122991894288933400L;
      String owner;
      String form;

      public Order(String owner,String form) {
      this.owner = owner;
      this.form = form;
      }

      public String getOwner() {
      return owner;
      }

      public void setOwner(String owner) {
      this.owner = owner;
      }

      public String getForm() {
      return form;
      }

      public void setForm(String form) {
      this.form = form;
      }
      }



      package taskassign;
      import java.util.ArrayList;
      import java.util.HashMap;
      import java.util.List;
      import java.util.Map;
      import java.util.Set;

      import org.jbpm.api.Configuration;
      import org.jbpm.api.Execution;
      import org.jbpm.api.ExecutionService;
      import org.jbpm.api.HistoryService;
      import org.jbpm.api.IdentityService;
      import org.jbpm.api.ManagementService;
      import org.jbpm.api.ProcessDefinition;
      import org.jbpm.api.ProcessDefinitionQuery;
      import org.jbpm.api.ProcessEngine;
      import org.jbpm.api.ProcessInstance;
      import org.jbpm.api.ProcessInstanceQuery;
      import org.jbpm.api.RepositoryService;
      import org.jbpm.api.TaskService;
      import org.jbpm.api.cmd.CommandService;
      import org.jbpm.api.task.Task;

      public class TestUpdate {

      protected ProcessEngine processEngine = null;

      protected RepositoryService repositoryService;
      protected ExecutionService executionService;
      protected ManagementService managementService;
      protected TaskService taskService;
      protected HistoryService historyService;
      protected IdentityService identityService;
      protected CommandService commandService;
      long deploymentDbid;
      protected List registeredDeployments = new ArrayList();
      protected ProcessInstance processInstance;

      /**
      * @param args
      */
      public static void main(String[] args) {
      // TODO Auto-generated method stub
      TestUpdate test = new TestUpdate();
      test.init();
      test.doCreate();

      //test.doCheckTask("hexiaof");
      //test.doCheckTask("hexiaofeng");

      test.doTaskAssign();
      test.doCheckTask("hexiaof");
      //test.doCheckTask("hexiaofeng");

      test.searchPID();
      test.doTaskReview();
      //test.doCheckTask("hexiaof");
      test.doCheckTask("hexiaofeng");
      test.doCompleteTask();

      test.del();

      }

      private void init() {

      processEngine = new Configuration().buildProcessEngine();

      repositoryService = processEngine.get(RepositoryService.class);
      executionService = processEngine.getExecutionService();
      historyService = processEngine.getHistoryService();
      managementService = processEngine.getManagementService();
      taskService = processEngine.getTaskService();
      identityService = processEngine.getIdentityService();
      commandService = processEngine.get(CommandService.class);

      deploymentDbid = repositoryService.createDeployment()
      .addResourceFromClasspath("taskassign/process.jpdl.xml").deploy();

      processInstance = executionService
      .startProcessInstanceByKey("TaskDemo");
      processInstance = executionService
      .startProcessInstanceByKey("TaskDemo","asd");
      System.out.println("processInstance.getId===========:"+processInstance.getId());
      System.out.println("deploymentDbid===========:"+deploymentDbid);
      }



      private void doCreate() {
      System.out.println("<<<=====doCreate=====");
      Map<String, Object> variables = new HashMap<String, Object>();
      variables.put("order", new Order("hexiaof","formID"));
      variables.put("form", "formID");
      String executionId = processInstance.findActiveExecutionIn("create").getId();
      processInstance = executionService.signalExecutionById(executionId,
      "toTaskAssign",variables);
      System.out.println("TaskAssign is " + processInstance.isActive("TaskAssign"));
      }

      private void doCheckTask(String username){
      System.out.println("<<<=====doCheckTask=====:"+username);
      List taskList = taskService.findPersonalTasks(username);
      System.out.println(username+"=====tasks number=====:"+taskList.size());

      Task task = null;
      long taskDBId = -1;
      for(int i=0;i<taskList.size();i++){
      task = taskList.get(i);
      System.out.println("=====tasks getName=====:"+task.getName());
      System.out.println("=====tasks getForm=====:"+task.getForm());
      System.out.println("=====tasks getDescription=====:"+task.getDescription());
      System.out.println("=====tasks getPriority=====:"+task.getPriority());
      System.out.println("=====tasks getPriority=====:"+task.getAssignee());
      taskDBId = task.getDbid();
      System.out.println("=====tasks getDbid=====:"+taskDBId);

      Set variableNames = taskService.getVariableNames(taskDBId);
      Map<String, Object> variables = taskService.getVariables(taskDBId, variableNames);
      System.out.println("form value is "+variables.get("form"));
      taskService.completeTask(taskDBId);

      System.out.println(username+" complete the task:"+task.getName());
      }
      taskList = taskService.findPersonalTasks(username);
      System.out.println(username+"=====tasks number=====:"+taskList.size());

      }

      private void doTaskAssign() {
      System.out.println("<<<=====doTaskAssign=====");
      Map<String, Object> variables = new HashMap<String, Object>();
      variables.put("order", new Order("hexiaofeng","123"));
      variables.put("formID", "formID123123");
      String executionId = processInstance.findActiveExecutionIn("TaskAssign").getId();
      processInstance = executionService.signalExecutionById(executionId,
      "toTaskReview",variables);
      System.out.println("TaskReview is " + processInstance.isActive("TaskReview"));
      }

      private void doTaskReview() {
      System.out.println("<<<=====doTaskReview=====");
      ProcessInstance pi = processEngine.getExecutionService().findProcessInstanceById(this.processInstance.getId());
      String executionId = pi.findActiveExecutionIn("TaskReview").getId();
      processInstance = executionService.signalExecutionById(executionId,
      "tocompleteTask");
      System.out.println("End is " + processInstance.isActive("completeTask"));
      }

      private void doCompleteTask() {
      System.out.println("<<<=====docompleteTask=====");
      String executionId = processInstance.findActiveExecutionIn("completeTask").getId();
      processInstance = executionService.signalExecutionById(executionId,
      "toEnd");
      System.out.println("End is " + processInstance.isActive("End"));
      }

      private void del(){
      System.out.println("<<<=====del=====");
      ProcessInstance pi = processEngine.getExecutionService().findProcessInstanceById(this.processInstance.getId());
      String executionId = pi.findActiveExecutionIn("End").getId();
      processInstance = executionService.signalExecutionById(executionId);
      //
      executionService.endProcessInstance(this.processInstance.getId(),"end");
      //repositoryService.deleteDeployment(this.deploymentDbid);
      }
      }

      I add "----" in xml. if you want to try it, please remove "----".

      <===?xml version="1.0" encoding="UTF-8"?>

      <----process name="TaskDemo" xmlns="http://jbpm.org/4.0/jpdl">

      <----start>
      <----transition to="create">
      <----/start>


      <----state name="create">
      <----transition name="toTaskAssign" to="TaskAssign">
      <----/state>

      <----task name="TaskAssign" assignee="#{order.owner}">
      <----transition name="toTaskReview" to="TaskReview">
      <----/task>

      <----task name="TaskReview" assignee="#{order.owner}">
      <----transition name="tocompleteTask" to="completeTask">
      <----/task>

      <----state name="completeTask">
      <----transition name="toEnd" to="End">
      <----/state>

      <----end name="End">

      <----/process>


      2009-7-8 10:23:56 org.hibernate.util.JDBCExceptionReporter logExceptions
      WARNING: SQL Error: 1451, SQLState: 23000
      2009-7-8 10:23:56 org.hibernate.util.JDBCExceptionReporter logExceptions
      SEVERE: Cannot delete or update a parent row: a foreign key constraint fails (`jbpm4/jbpm4_execution`, CONSTRAINT `FK_EXEC_INSTANCE` FOREIGN KEY (`INSTANCE_`) REFERENCES `jbpm4_execution` (`DBID_`))
      2009-7-8 10:23:56 org.hibernate.event.def.AbstractFlushingEventListener performExecutions
      SEVERE: Could not synchronize database state with session
      Throwable occurred: org.hibernate.exception.ConstraintViolationException: could not delete: [org.jbpm.jpdl.internal.model.JpdlExecution#2]
      at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)
      at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
      at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2569)
      at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2725)
      at org.hibernate.action.EntityDeleteAction.execute(EntityDeleteAction.java:97)
      at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:172)
      at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
      at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
      at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
      at org.jbpm.pvm.internal.tx.HibernateSessionResource.prepare(HibernateSessionResource.java:54)
      at org.jbpm.pvm.internal.tx.StandardTransaction.commit(StandardTransaction.java:106)
      at org.jbpm.pvm.internal.tx.StandardTransaction.complete(StandardTransaction.java:65)
      at org.jbpm.pvm.internal.tx.StandardTransactionInterceptor.execute(StandardTransactionInterceptor.java:61)
      at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:54)
      at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:55)
      at org.jbpm.pvm.internal.svc.ExecutionServiceImpl.signalExecutionById(ExecutionServiceImpl.java:87)
      at taskassign.TestUpdate.doCompleteTask(TestUpdate.java:169)
      at taskassign.TestUpdate.main(TestUpdate.java:59)
      Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`jbpm4/jbpm4_execution`, CONSTRAINT `FK_EXEC_INSTANCE` FOREIGN KEY (`INSTANCE_`) REFERENCES `jbpm4_execution` (`DBID_`))
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:931)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
      at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
      at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
      at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
      at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
      at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1604)
      at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1519)
      at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1504)
      at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2551)
      ... 17 more
      Exception in thread "main" org.hibernate.exception.ConstraintViolationException: could not delete: [org.jbpm.jpdl.internal.model.JpdlExecution#2]
      at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)
      at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
      at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2569)
      at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2725)
      at org.hibernate.action.EntityDeleteAction.execute(EntityDeleteAction.java:97)
      at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:172)
      at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
      at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
      at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
      at org.jbpm.pvm.internal.tx.HibernateSessionResource.prepare(HibernateSessionResource.java:54)
      at org.jbpm.pvm.internal.tx.StandardTransaction.commit(StandardTransaction.java:106)
      at org.jbpm.pvm.internal.tx.StandardTransaction.complete(StandardTransaction.java:65)
      at org.jbpm.pvm.internal.tx.StandardTransactionInterceptor.execute(StandardTransactionInterceptor.java:61)
      at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:54)
      at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:55)
      at org.jbpm.pvm.internal.svc.ExecutionServiceImpl.signalExecutionById(ExecutionServiceImpl.java:87)
      at taskassign.TestUpdate.doCompleteTask(TestUpdate.java:169)
      at taskassign.TestUpdate.main(TestUpdate.java:59)
      Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`jbpm4/jbpm4_execution`, CONSTRAINT `FK_EXEC_INSTANCE` FOREIGN KEY (`INSTANCE_`) REFERENCES `jbpm4_execution` (`DBID_`))
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:931)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
      at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
      at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
      at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
      at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
      at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1604)
      at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1519)
      at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1504)
      at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2551)
      ... 17 more

        • 1. Re: JBPM4: FOREIGN KEY problem
          kukeltje

          have you searched the forum and jira for similar isues? There have been and I wonder if they are related.

          • 2. Re: JBPM4: FOREIGN KEY problem

            no found similar isues in forum. Who can give me some suggests? Thanks

            • 3. Re: JBPM4: FOREIGN KEY problem
              shekharv

              I do not have any problems on MySql.

              I would attempt to recreate the tables once, or delete all the data in there once,

              and try again,

              Is the latest code that you were trying?

              • 4. Re: JBPM4: FOREIGN KEY problem

                hi sheharv.

                Thanks for you comment.
                Can you try my codes in your MySQL? Thank you very much.
                I delete all tables. I use jbpm.mysql.drop.sql to do that.

                If you find bug in my codes, Please help me to fix it.My codes are very simple, If you update my codes. Please post it . Thank you again.

                • 5. Re: JBPM4: FOREIGN KEY problem

                  hi sheharv

                  Thanks for your help.

                  Do you try my codes via your mysql? Do it still work fine?
                  I remove my tabels via use jbpm.mysql.drop.sql.
                  But exception still show.

                  So can you help me to check my codes? I guess maybe some bug in my codes.

                  Thank you agan.

                  • 6. Re: JBPM4: FOREIGN KEY problem
                    shekharv

                    OK, well I could not sleep, so I did try your code out, and it worked. Within Mysql.
                    Your code was unchanged except for the fact that there was a method that you did not put in the earlier post. test.PID(). You did not put that method in the post you had.
                    Here's the jbpm.hibernate.cfg.xml i had:

                    <?xml version="1.0" encoding="utf-8"?>
                    
                    <!DOCTYPE hibernate-configuration PUBLIC
                     "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                     "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
                    
                    <hibernate-configuration>
                     <session-factory>
                    
                     <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
                     <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
                     <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/jbpm</property>
                     <property name="hibernate.connection.username">root</property>
                     <property name="hibernate.connection.password"></property>
                     <property name="hibernate.format_sql">true</property>
                    
                     <mapping resource="jbpm.repository.hbm.xml"/>
                     <mapping resource="jbpm.execution.hbm.xml"/>
                     <mapping resource="jbpm.history.hbm.xml"/>
                     <mapping resource="jbpm.task.hbm.xml"/>
                     <mapping resource="jbpm.jpdl.hbm.xml"/>
                     <mapping resource="jbpm.identity.hbm.xml"/>
                    
                     </session-factory>
                    </hibernate-configuration>
                    
                    


                    package org.jbpm.examples.task.assignee;
                    
                    import org.jbpm.api.Configuration;
                    import org.jbpm.api.ExecutionService;
                    import org.jbpm.api.HistoryService;
                    import org.jbpm.api.IdentityService;
                    import org.jbpm.api.ManagementService;
                    import org.jbpm.api.ProcessEngine;
                    import org.jbpm.api.ProcessInstance;
                    import org.jbpm.api.RepositoryService;
                    import org.jbpm.api.TaskService;
                    import org.jbpm.api.task.Task;
                    import org.jbpm.api.cmd.CommandService;
                    
                    import java.util.ArrayList;
                    import java.util.HashMap;
                    import java.util.List;
                    import java.util.Map;
                    import java.util.Set;
                    
                    /**
                     * Created by IntelliJ IDEA.
                     * User: svemuri
                     * Date: Jul 8, 2009
                     * Time: 10:04:22 PM
                     */
                    public class TestUpdate {
                    
                     protected ProcessEngine processEngine = null;
                    
                     protected RepositoryService repositoryService;
                     protected ExecutionService executionService;
                     protected ManagementService managementService;
                     protected TaskService taskService;
                     protected HistoryService historyService;
                     protected IdentityService identityService;
                     protected CommandService commandService;
                     long deploymentDbid;
                     protected List registeredDeployments = new ArrayList();
                     protected ProcessInstance processInstance;
                    
                     /**
                     * @param args
                     */
                     public static void main(String[] args) {
                    // TODO Auto-generated method stub
                     TestUpdate test = new TestUpdate();
                     test.init();
                     test.doCreate();
                    
                    //test.doCheckTask("hexiaof");
                    //test.doCheckTask("hexiaofeng");
                    
                     test.doTaskAssign();
                     test.doCheckTask("hexiaof");
                    //test.doCheckTask("hexiaofeng");
                    
                     //test.searchPID();
                     test.doTaskReview();
                    //test.doCheckTask("hexiaof");
                     test.doCheckTask("hexiaofeng");
                     test.doCompleteTask();
                    
                     test.del();
                    
                     }
                    
                     private void init() {
                    
                     processEngine = new Configuration().buildProcessEngine();
                    
                     repositoryService = processEngine.get(RepositoryService.class);
                     executionService = processEngine.getExecutionService();
                     historyService = processEngine.getHistoryService();
                     managementService = processEngine.getManagementService();
                     taskService = processEngine.getTaskService();
                     identityService = processEngine.getIdentityService();
                     commandService = processEngine.get(CommandService.class);
                    
                     deploymentDbid = repositoryService.createDeployment()
                     .addResourceFromClasspath("org/jbpm/examples/task/assignee/process.jpdl.xml").deploy();
                    
                     processInstance = executionService
                     .startProcessInstanceByKey("TaskDemo");
                     processInstance = executionService
                     .startProcessInstanceByKey("TaskDemo", "123345");
                     System.out.println("processInstance.getId===========:" + processInstance.getId());
                     System.out.println("deploymentDbid===========:" + deploymentDbid);
                     }
                    
                    
                     private void doCreate() {
                     System.out.println("<<<=====doCreate=====");
                     Map<String, Object> variables = new HashMap<String, Object>();
                     variables.put("order", new Order("hexiaof"));
                     variables.put("form", "formID");
                     String executionId = processInstance.findActiveExecutionIn("create").getId();
                     processInstance = executionService.signalExecutionById(executionId,
                     "toTaskAssign", variables);
                     System.out.println("TaskAssign is " + processInstance.isActive("TaskAssign"));
                     }
                    
                     private void doCheckTask(String username) {
                     System.out.println("<<<=====doCheckTask=====:" + username);
                     List<Task> taskList = taskService.findPersonalTasks(username);
                     System.out.println(username + "=====tasks number=====:" + taskList.size());
                    
                     Task task = null;
                     long taskDBId = -1;
                     for (int i = 0; i < taskList.size(); i++) {
                     task = taskList.get(i);
                     System.out.println("=====tasks getName=====:" + task.getName());
                     System.out.println("=====tasks getForm=====:" + task.getForm());
                     System.out.println("=====tasks getDescription=====:" + task.getDescription());
                     System.out.println("=====tasks getPriority=====:" + task.getPriority());
                     System.out.println("=====tasks getPriority=====:" + task.getAssignee());
                     taskDBId = task.getDbid();
                     System.out.println("=====tasks getDbid=====:" + taskDBId);
                    
                     Set variableNames = taskService.getVariableNames(taskDBId);
                     Map<String, Object> variables = taskService.getVariables(taskDBId, variableNames);
                     System.out.println("form value is " + variables.get("form"));
                     taskService.completeTask(taskDBId);
                    
                     System.out.println(username + " complete the task:" + task.getName());
                     }
                     taskList = taskService.findPersonalTasks(username);
                     System.out.println(username + "=====tasks number=====:" + taskList.size());
                    
                     }
                    
                     private void doTaskAssign() {
                     System.out.println("<<<=====doTaskAssign=====");
                     Map<String, Object> variables = new HashMap<String, Object>();
                     variables.put("order", new Order("hexiaofeng"));
                     variables.put("formID", "formID123123");
                     String executionId = processInstance.findActiveExecutionIn("TaskAssign").getId();
                     processInstance = executionService.signalExecutionById(executionId,
                     "toTaskReview", variables);
                     System.out.println("TaskReview is " + processInstance.isActive("TaskReview"));
                     }
                    
                     private void doTaskReview() {
                     System.out.println("<<<=====doTaskReview=====");
                     ProcessInstance pi = processEngine.getExecutionService().findProcessInstanceById(this.processInstance.getId());
                     String executionId = pi.findActiveExecutionIn("TaskReview").getId();
                     processInstance = executionService.signalExecutionById(executionId,
                     "tocompleteTask");
                     System.out.println("End is " + processInstance.isActive("completeTask"));
                     }
                    
                     private void doCompleteTask() {
                     System.out.println("<<<=====docompleteTask=====");
                     String executionId = processInstance.findActiveExecutionIn("completeTask").getId();
                     processInstance = executionService.signalExecutionById(executionId,
                     "toEnd");
                     System.out.println("End is " + processInstance.isActive("End"));
                     }
                    
                     private void del() {
                     System.out.println("<<<=====del=====");
                     ProcessInstance pi = processEngine.getExecutionService().findProcessInstanceById(this.processInstance.getId());
                     String executionId = pi.findActiveExecutionIn("end").getId();
                     processInstance = executionService.signalExecutionById(executionId);
                    //
                     executionService.endProcessInstance(this.processInstance.getId(), "end");
                    //repositoryService.deleteDeployment(this.deploymentDbid);
                     }
                    }
                    


                    The above example fails at the line that tries to load a ProcessInstance that does not even exist in the db, coz it's ended and has been deleted.

                    processInstance.getId===========:TaskDemo.asdd
                    deploymentDbid===========:6
                    <<<=====doCreate=====
                    01:56:25,173 FIN | [Signal] signalling activity(create), signalName=toTaskAssign
                    01:56:25,173 FIN | [ScopeInstanceImpl] create variable 'form' in 'process-instance' with value 'formID'
                    01:56:25,174 FIN | [ScopeInstanceImpl] create variable 'order' in 'process-instance' with value 'org.jbpm.examples.task.assignee.Order@74b1a7a0'
                    01:56:25,267 FIN | [ExecuteActivity] executing activity(TaskAssign)
                    TaskAssign is true
                    <<<=====doTaskAssign=====
                    01:56:25,329 FIN | [Signal] signalling activity(TaskAssign), signalName=toTaskReview
                    01:56:25,332 FIN | [ScopeInstanceImpl] updating variable 'order' in 'process-instance' to value 'org.jbpm.examples.task.assignee.Order@38a88c32'
                    01:56:25,337 FIN | [ScopeInstanceImpl] create variable 'formID' in 'process-instance' with value 'formID123123'
                    01:56:25,345 FIN | [ExecuteActivity] executing activity(TaskReview)
                    TaskReview is true
                    <<<=====doCheckTask=====:hexiaof
                    01:56:25,355 FIN | [TaskQueryImpl] select distinct task from org.jbpm.pvm.internal.task.TaskImpl as task where task.state != 'suspended' and task.assignee = :assignee order by task.priority desc
                    01:56:25,362 FIN | [TaskQueryImpl] setting parameter assignee: hexiaof
                    hexiaof=====tasks number=====:1
                    =====tasks getName=====:TaskAssign
                    =====tasks getForm=====:null
                    =====tasks getDescription=====:null
                    =====tasks getPriority=====:0
                    =====tasks getPriority=====:hexiaof
                    =====tasks getDbid=====:3
                    form value is formID
                    hexiaof complete the task:TaskAssign
                    01:56:25,417 FIN | [TaskQueryImpl] select distinct task from org.jbpm.pvm.internal.task.TaskImpl as task where task.state != 'suspended' and task.assignee = :assignee order by task.priority desc
                    01:56:25,417 FIN | [TaskQueryImpl] setting parameter assignee: hexiaof
                    hexiaof=====tasks number=====:0
                    <<<=====doTaskReview=====
                    01:56:25,427 FIN | [Signal] signalling activity(TaskReview), signalName=tocompleteTask
                    01:56:25,429 FIN | [ExecuteActivity] executing activity(completeTask)
                    End is true
                    <<<=====doCheckTask=====:hexiaofeng
                    01:56:25,433 FIN | [TaskQueryImpl] select distinct task from org.jbpm.pvm.internal.task.TaskImpl as task where task.state != 'suspended' and task.assignee = :assignee order by task.priority desc
                    01:56:25,433 FIN | [TaskQueryImpl] setting parameter assignee: hexiaofeng
                    hexiaofeng=====tasks number=====:1
                    =====tasks getName=====:TaskReview
                    =====tasks getForm=====:null
                    =====tasks getDescription=====:null
                    =====tasks getPriority=====:0
                    =====tasks getPriority=====:hexiaofeng
                    =====tasks getDbid=====:4
                    form value is formID
                    hexiaofeng complete the task:TaskReview
                    01:56:25,465 FIN | [TaskQueryImpl] select distinct task from org.jbpm.pvm.internal.task.TaskImpl as task where task.state != 'suspended' and task.assignee = :assignee order by task.priority desc
                    01:56:25,465 FIN | [TaskQueryImpl] setting parameter assignee: hexiaofeng
                    hexiaofeng=====tasks number=====:0
                    <<<=====docompleteTask=====
                    01:56:25,471 FIN | [Signal] signalling activity(completeTask), signalName=toEnd
                    01:56:25,473 FIN | [ExecuteActivity] executing activity(End)
                    01:56:25,473 FIN | [Execution] process-instance ends with state ended
                    01:56:25,489 FIN | [DbSessionImpl] deleting process instance TaskDemo.asdd
                    End is false
                    <<<=====del=====
                    Exception in thread "main" java.lang.NullPointerException
                     at org.jbpm.examples.task.assignee.TestUpdate.del(TestUpdate.java:163)
                     at org.jbpm.examples.task.assignee.TestUpdate.main(TestUpdate.java:64)
                    


                    • 7. Re: JBPM4: FOREIGN KEY problem
                      shekharv

                      as I said, I did check it with mysql, it says so in the hibernate config.

                      Can you try in a different database? Hsql? the stuff that jbpm comes with default?

                      <?xml version="1.0" encoding="utf-8"?>
                      
                      <!DOCTYPE hibernate-configuration PUBLIC
                       "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                       "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
                      
                      <hibernate-configuration>
                       <session-factory>
                      
                       <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
                       <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
                       <property name="hibernate.connection.url">jdbc:hsqldb:mem:.</property>
                       <property name="hibernate.connection.username">sa</property>
                       <property name="hibernate.connection.password"></property>
                       <property name="hibernate.hbm2ddl.auto">create-drop</property>
                       <property name="hibernate.format_sql">true</property>
                       <!--<property name="hibernate.show_sql">true</property>-->
                      
                       <mapping resource="jbpm.repository.hbm.xml" />
                       <mapping resource="jbpm.execution.hbm.xml" />
                       <mapping resource="jbpm.history.hbm.xml" />
                       <mapping resource="jbpm.task.hbm.xml" />
                       <mapping resource="jbpm.jpdl.hbm.xml" />
                       <mapping resource="jbpm.identity.hbm.xml" />
                      
                       </session-factory>
                      </hibernate-configuration>
                      
                      


                      • 8. Re: JBPM4: FOREIGN KEY problem
                        shekharv

                        I am using jbpm 4 cr1.

                        • 9. Re: JBPM4: FOREIGN KEY problem

                          Thank you very much.

                          Can you tell me how to fix the java.lang.NullPointerException? I am very puzzle..

                          • 10. Re: JBPM4: FOREIGN KEY problem
                            shekharv

                            Once you have completed the last task in the process, the process goes to the end sate after which it is deleted from the jbpm4_execution table and is then put into the JBPM4_HIST_PROCINST table,

                            Now here are the two lines that are causing the problem: this is in the del method:

                            ProcessInstance pi = processEngine.getExecutionService().findProcessInstanceById(this.processInstance.getId());
                            String executionId = pi.findActiveExecutionIn("end").getId();

                            The process instance has been deleted, as it has ended. IF it is deleted, the pi object is null and hence it throws a NPE,

                            • 11. Re: JBPM4: FOREIGN KEY problem

                              Thanks , I know hot to do it.. Thank you again. :-)

                              • 12. Re: JBPM4: FOREIGN KEY problem

                                I fixed it. Thank you

                                • 13. Re: JBPM4: FOREIGN KEY problem
                                  shekharv

                                  I assume, you fixed it, by doing what was recommended?

                                  Just so that it might help others too,