[jboss-user] [JBoss jBPM] - Re: JBPM4: FOREIGN KEY problem

shekharv do-not-reply at jboss.com
Thu Jul 9 04:57:41 EDT 2009


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 at 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 at 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)
  | 

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4242548#4242548

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4242548



More information about the jboss-user mailing list