Cannot access process instance after calling CompleteTask(), Why?
djigit Dec 16, 2009 10:43 AMHi all,
I am a new user of this JBPM forum and JBPM itself. I am trying to integrate JBPM 4 to my JEE project.
But first tried out some simple examples to be familiar with JBPM 4. I am using:
jbpm-4.2
jboss-5.1.0.GA
eclipse 3.5
So, here is my question:
With the following process definition and test class,
{code:xml}
<?xml version="1.0" encoding="UTF-8"?>
<process name="demoProcess" xmlns="http://jbpm.org/4.2/jpdl">
<start g="93,122,48,48" name="start1">
<transition name="to end1" to="end1" g="-45,-20"/>
</start>
<end g="326,133,48,48" name="end1" state="normal_completed"/>
</process>
{code}
{code:java}
public class JbpmTest {
public static void main(String[] args)
{
ProcessEngine processEngine = new Configuration().buildProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
ExecutionService executionService = processEngine.getExecutionService();
String deploymentID = repositoryService.createDeployment().addResourceFromClasspath("demoProcess.jpdl.xml").deploy();
ProcessInstance processInstance = executionService.startProcessInstanceByKey("demoProcess");
System.out.println("--------------------- processInstance : " + processInstance);
System.out.println("--------------------- processInstance getId : " + processInstance.getId());
System.out.println("--------------------- processInstance getState : " + processInstance.getState());
System.out.println("--------------------- processInstance isEnded : " + processInstance.isEnded());
repositoryService.deleteDeploymentCascade(deploymentID);
}
}
{code}
Got the following output:
--------------------- processInstance : execution[demoProcess.1]
--------------------- processInstance getId : demoProcess.1
--------------------- processInstance getState : normal_completed
--------------------- processInstance isEnded : true
But when i added a task, could not access to process instance,
as in the following process definiton and test class:
{code:xml}
<?xml version="1.0" encoding="UTF-8"?>
<process name="demoProcess" xmlns="http://jbpm.org/4.2/jpdl">
<start g="93,122,48,48" name="start1">
<transition name="to some task" to="some task" g="-72,-20"/>
</start>
<task name="some task" assignee="er" g="299,121,92,52">
<transition name="to end1" to="end1" g="-45,-20"/>
</task>
<end g="578,123,48,48" name="end1" state="normal_completed"/>
</process>
{code}
{code:java}
public class JbpmTest {
public static void main(String[] args)
{
ProcessEngine processEngine = new Configuration().buildProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
ExecutionService executionService = processEngine.getExecutionService();
TaskService taskService = processEngine.getTaskService();
String deploymentID = repositoryService.createDeployment().addResourceFromClasspath("demoProcess.jpdl.xml").deploy();
ProcessInstance processInstance = executionService.startProcessInstanceByKey("demoProcess");
String pID = processInstance.getId();
System.out.println("(before completeTask) processInstance : " + processInstance);
System.out.println("(before completeTask) processInstance getId : " + processInstance.getId());
System.out.println("(before completeTask) processInstance getState : " + processInstance.getState());
System.out.println("(before completeTask) processInstance isEnded : " + processInstance.isEnded());
List<Task> taskList = taskService.findPersonalTasks("er");
Task task = taskList.get(0);
System.out.println("----- task : " + task);
System.out.println("----- task getId : " + task.getId());
System.out.println("----- task getName : " + task.getName());
System.out.println("----- task getActivityName : " + task.getActivityName());
System.out.println("----- task getAssignee : " + task.getAssignee());
taskService.completeTask(task.getId());
processInstance = executionService.findProcessInstanceById(pID);
System.out.println("(after completeTask) processInstance : " + processInstance);
System.out.println("(after completeTask) processInstance getId : " + processInstance.getId());
System.out.println("(after completeTask) processInstance getState : " + processInstance.getState());
System.out.println("(after completeTask) processInstance isEnded : " + processInstance.isEnded());
repositoryService.deleteDeploymentCascade(deploymentID);
}
}
{code}
Output is:
(before completeTask) processInstance : execution[demoProcess.1]
(before completeTask) processInstance getId : demoProcess.1
(before completeTask) processInstance getState : active-root
(before completeTask) processInstance isEnded : false
----- task : Task(some task)
----- task getId : 1
----- task getName : some task
----- task getActivityName : some task
----- task getAssignee : er
(after completeTask) processInstance : null
Exception in thread "main" java.lang.NullPointerException
at com.tutorial.JbpmTest.main(JbpmTest.java:51)
As i know completeTask deletes the task from the DB, not a processInstance.
If processInstance is deleted because there is no wait state after the task,
then why i can acces to processInstance in a first case?
That is all for now. Thanks in advance for any suggestions..
p.s. As you guess, my english is not the best .