I have implemented a Camunda ServiceTask class (JavaDelegate) right after the start of my process. In this task I run a ProcessInstanceQuery for the own process instance (don't ask why). Surprisingly the query result is null - and I do not understand how this can happen.
To reproduce the problem I created a very simple demo project at GitHub.
This is the process
and this is my HelloWorldTask execution code
@Override
public void execute(DelegateExecution execution) throws Exception {
String processInstanceId = execution.getProcessInstanceId();
System.out.println(
"Entering HelloWorldTask.execute (processInstanceId=" + processInstanceId + ")");
ProcessInstanceQuery query =
runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId);
ProcessInstance pi = query.singleResult();
if (pi == null) {
System.out
.println("WARN - No process instance with id " + processInstanceId + " found!");
} else {
System.out.println("Hello World!");
}
System.out.println(
"Exiting HelloWorldTask.execute (processInstanceId=" + processInstanceId + ")");
}
There is a unit test hello.word.HelloWorldTest.helloWorld()
which can be used to start the process. The output unfortunately is
Entering HelloWorldTask.execute (processInstanceId=4)
WARN - No process instance with id 4 found!
Exiting HelloWorldTask.execute (processInstanceId=4)
Can anyone explain this behaviour. Would be very helpful for me.