Context.getCommandContext() returning null
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2013 06:17 PM
I am encountering a situation where during certain operations Context.getCommandContext() is return null. I am not using a activity.cfg.xml file in my project and am building the ProcessEngineConfiguration programatically and then using guice to inject it where needed.
I can run a process to cpmpletion without any issues, but when I try to get an execution's super execution I see this:
java.lang.NullPointerException
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.ensureSuperExecutionInitialized(ExecutionEntity.java:768)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.getSuperExecution(ExecutionEntity.java:749)
I'm not sure what the cause here is. I am using 5.13
I'd appreciate any guidance here.
I can run a process to cpmpletion without any issues, but when I try to get an execution's super execution I see this:
java.lang.NullPointerException
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.ensureSuperExecutionInitialized(ExecutionEntity.java:768)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.getSuperExecution(ExecutionEntity.java:749)
I'm not sure what the cause here is. I am using 5.13
I'd appreciate any guidance here.
Labels:
- Labels:
-
Archive
8 REPLIES 8
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2013 03:00 AM
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-18-2013 09:08 PM
@Test
public void testGetChildExecutions() throws Exception {
// Deploy child Process
File processFile =
new File(TestUtil.getSrcDir() + TEST_PROCESS_FOLDER + "test_sub_call_activity_process.bpmn");
String processStr = readFile(processFile);
DeploymentBuilder builder = repositoryService.createDeployment()
.name(DEPLOYMENT_NAME).addString(DEPLOYMENT_NAME, processStr);
builder.deploy();
// Deploy parent Process
processFile =
new File(TestUtil.getSrcDir() + TEST_PROCESS_FOLDER + "test_call_activity_process.bpmn");
processStr = readFile(processFile);
builder = repositoryService.createDeployment()
.name(DEPLOYMENT_NAME).addString(DEPLOYMENT_NAME, processStr);
String deploymentId = builder.deploy().getId();
// Start parent process instance
List<ProcessDefinition> definitions = repositoryService.createProcessDefinitionQuery()
.deploymentId(deploymentId)
.orderByProcessDefinitionVersion()
.desc()
.list();
ProcessDefinition definition = definitions.get(0);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(definition.getKey());
List<Execution> executions = runtimeService.createNativeExecutionQuery().sql("SELECT * FROM "
+ managementService.getTableName(Execution.class) + " WHERE PROC_INST_ID_ = #{processInstanceId}")
.parameter("processInstanceId", processInstance.getId()).list();
assertEquals(1, executions.size());
// Move to second task which is a call activity to call sub process
Execution rootExecution = executions.get(0);
runtimeService.signal(rootExecution.getId(), null);
processInstance = (ProcessInstance) runtimeService.createExecutionQuery()
.executionId(rootExecution.getId()).singleResult();
executions = runtimeService.createNativeExecutionQuery().sql("SELECT * FROM "
+ managementService.getTableName(Execution.class) + " WHERE PROC_INST_ID_ = #{processInstanceId}")
.parameter("processInstanceId", processInstance.getId()).list();
assertEquals(2, executions.size());
List<Execution> subExecutions = runtimeService.createNativeExecutionQuery().sql("SELECT * FROM "
+ managementService.getTableName(Execution.class) + " WHERE SUPER_EXEC_ = #{executionId}")
.parameter("executionId", executions.get(1).getId()).list();
ExecutionEntity currentExecution = (ExecutionEntity) subExecutions.get(0);
if (currentExecution.getSuperExecutionId() != null) {
ExecutionEntity superExecution = currentExecution.getSuperExecution();
}
}
The error happens in the last line. I am trying to write code to get all the parent executions of a given process. The parent process in this test calls the child process using a call activity node in its second task. Please let me know if I can provide more info.
public void testGetChildExecutions() throws Exception {
// Deploy child Process
File processFile =
new File(TestUtil.getSrcDir() + TEST_PROCESS_FOLDER + "test_sub_call_activity_process.bpmn");
String processStr = readFile(processFile);
DeploymentBuilder builder = repositoryService.createDeployment()
.name(DEPLOYMENT_NAME).addString(DEPLOYMENT_NAME, processStr);
builder.deploy();
// Deploy parent Process
processFile =
new File(TestUtil.getSrcDir() + TEST_PROCESS_FOLDER + "test_call_activity_process.bpmn");
processStr = readFile(processFile);
builder = repositoryService.createDeployment()
.name(DEPLOYMENT_NAME).addString(DEPLOYMENT_NAME, processStr);
String deploymentId = builder.deploy().getId();
// Start parent process instance
List<ProcessDefinition> definitions = repositoryService.createProcessDefinitionQuery()
.deploymentId(deploymentId)
.orderByProcessDefinitionVersion()
.desc()
.list();
ProcessDefinition definition = definitions.get(0);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(definition.getKey());
List<Execution> executions = runtimeService.createNativeExecutionQuery().sql("SELECT * FROM "
+ managementService.getTableName(Execution.class) + " WHERE PROC_INST_ID_ = #{processInstanceId}")
.parameter("processInstanceId", processInstance.getId()).list();
assertEquals(1, executions.size());
// Move to second task which is a call activity to call sub process
Execution rootExecution = executions.get(0);
runtimeService.signal(rootExecution.getId(), null);
processInstance = (ProcessInstance) runtimeService.createExecutionQuery()
.executionId(rootExecution.getId()).singleResult();
executions = runtimeService.createNativeExecutionQuery().sql("SELECT * FROM "
+ managementService.getTableName(Execution.class) + " WHERE PROC_INST_ID_ = #{processInstanceId}")
.parameter("processInstanceId", processInstance.getId()).list();
assertEquals(2, executions.size());
List<Execution> subExecutions = runtimeService.createNativeExecutionQuery().sql("SELECT * FROM "
+ managementService.getTableName(Execution.class) + " WHERE SUPER_EXEC_ = #{executionId}")
.parameter("executionId", executions.get(1).getId()).list();
ExecutionEntity currentExecution = (ExecutionEntity) subExecutions.get(0);
if (currentExecution.getSuperExecutionId() != null) {
ExecutionEntity superExecution = currentExecution.getSuperExecution();
}
}
The error happens in the last line. I am trying to write code to get all the parent executions of a given process. The parent process in this test calls the child process using a call activity node in its second task. Please let me know if I can provide more info.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-18-2013 09:10 PM
With better formatting this time:
<java>
@Test
public void testGetChildExecutions() throws Exception {
// Deploy child Process
File processFile =
new File(TestUtil.getSrcDir() + TEST_PROCESS_FOLDER + "test_sub_call_activity_process.bpmn");
String processStr = readFile(processFile);
DeploymentBuilder builder = repositoryService.createDeployment()
.name(DEPLOYMENT_NAME).addString(DEPLOYMENT_NAME, processStr);
builder.deploy();
// Deploy parent Process
processFile =
new File(TestUtil.getSrcDir() + TEST_PROCESS_FOLDER + "test_call_activity_process.bpmn");
processStr = readFile(processFile);
builder = repositoryService.createDeployment()
.name(DEPLOYMENT_NAME).addString(DEPLOYMENT_NAME, processStr);
String deploymentId = builder.deploy().getId();
// Start parent process instance
List<ProcessDefinition> definitions = repositoryService.createProcessDefinitionQuery()
.deploymentId(deploymentId)
.orderByProcessDefinitionVersion()
.desc()
.list();
ProcessDefinition definition = definitions.get(0);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(definition.getKey());
List<Execution> executions = runtimeService.createNativeExecutionQuery().sql("SELECT * FROM "
+ managementService.getTableName(Execution.class) + " WHERE PROC_INST_ID_ = #{processInstanceId}")
.parameter("processInstanceId", processInstance.getId()).list();
assertEquals(1, executions.size());
// Move to second task which is a call activity to call sub process
Execution rootExecution = executions.get(0);
runtimeService.signal(rootExecution.getId(), null);
processInstance = (ProcessInstance) runtimeService.createExecutionQuery()
.executionId(rootExecution.getId()).singleResult();
executions = runtimeService.createNativeExecutionQuery().sql("SELECT * FROM "
+ managementService.getTableName(Execution.class) + " WHERE PROC_INST_ID_ = #{processInstanceId}")
.parameter("processInstanceId", processInstance.getId()).list();
assertEquals(2, executions.size());
List<Execution> subExecutions = runtimeService.createNativeExecutionQuery().sql("SELECT * FROM "
+ managementService.getTableName(Execution.class) + " WHERE SUPER_EXEC_ = #{executionId}")
.parameter("executionId", executions.get(1).getId()).list();
ExecutionEntity currentExecution = (ExecutionEntity) subExecutions.get(0);
if (currentExecution.getSuperExecutionId() != null) {
ExecutionEntity superExecution = currentExecution.getSuperExecution();
}
}
</java>
The error happens in the last line. I am trying to write code to get all the parent executions of a given process. The parent process in this test calls the child process using a call activity node in its second task. Please let me know if I can provide more info.
<java>
@Test
public void testGetChildExecutions() throws Exception {
// Deploy child Process
File processFile =
new File(TestUtil.getSrcDir() + TEST_PROCESS_FOLDER + "test_sub_call_activity_process.bpmn");
String processStr = readFile(processFile);
DeploymentBuilder builder = repositoryService.createDeployment()
.name(DEPLOYMENT_NAME).addString(DEPLOYMENT_NAME, processStr);
builder.deploy();
// Deploy parent Process
processFile =
new File(TestUtil.getSrcDir() + TEST_PROCESS_FOLDER + "test_call_activity_process.bpmn");
processStr = readFile(processFile);
builder = repositoryService.createDeployment()
.name(DEPLOYMENT_NAME).addString(DEPLOYMENT_NAME, processStr);
String deploymentId = builder.deploy().getId();
// Start parent process instance
List<ProcessDefinition> definitions = repositoryService.createProcessDefinitionQuery()
.deploymentId(deploymentId)
.orderByProcessDefinitionVersion()
.desc()
.list();
ProcessDefinition definition = definitions.get(0);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(definition.getKey());
List<Execution> executions = runtimeService.createNativeExecutionQuery().sql("SELECT * FROM "
+ managementService.getTableName(Execution.class) + " WHERE PROC_INST_ID_ = #{processInstanceId}")
.parameter("processInstanceId", processInstance.getId()).list();
assertEquals(1, executions.size());
// Move to second task which is a call activity to call sub process
Execution rootExecution = executions.get(0);
runtimeService.signal(rootExecution.getId(), null);
processInstance = (ProcessInstance) runtimeService.createExecutionQuery()
.executionId(rootExecution.getId()).singleResult();
executions = runtimeService.createNativeExecutionQuery().sql("SELECT * FROM "
+ managementService.getTableName(Execution.class) + " WHERE PROC_INST_ID_ = #{processInstanceId}")
.parameter("processInstanceId", processInstance.getId()).list();
assertEquals(2, executions.size());
List<Execution> subExecutions = runtimeService.createNativeExecutionQuery().sql("SELECT * FROM "
+ managementService.getTableName(Execution.class) + " WHERE SUPER_EXEC_ = #{executionId}")
.parameter("executionId", executions.get(1).getId()).list();
ExecutionEntity currentExecution = (ExecutionEntity) subExecutions.get(0);
if (currentExecution.getSuperExecutionId() != null) {
ExecutionEntity superExecution = currentExecution.getSuperExecution();
}
}
</java>
The error happens in the last line. I am trying to write code to get all the parent executions of a given process. The parent process in this test calls the child process using a call activity node in its second task. Please let me know if I can provide more info.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2013 06:11 AM
Is there a specific reason for not using our Query API? ProcessInstanceQuery also allows you to query for child and parent process instances.
Best regards,
Best regards,
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2013 08:48 PM
Yes, I am trying to get the complete chain of parents. So if the current execution is the result of concurrency, I want to get its parent execution (from the same process) and flag it for concurrency. If the current execution is because of a call activity then yes I can get the parent using process instance query like you said. If there is an easier to get the concurrency use case, or embedded process case as well, please let me know.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2013 10:05 AM
Ok fair enough. You would need to create a custom command context and wrap your call to get the super execution in there. Because Activiti needs a command context to retrieve the super execution.
Best regards,
Best regards,
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2013 01:24 PM
I see. I couldn't find info in the user guide on creating Custom Command Contexts. The CommandContext class itself also doesn't seem to have any children I can see as an example. Can you point me to any documentation on how to create, use and register custom command contexts?
I appreciate your help on this.
I appreciate your help on this.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2013 11:31 AM
Let me add an example from one of the Activiti test classes:
<blockcode>
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
ProcessDefinitionEntity processDefinitionEntity = commandExecutor.execute(new Command<ProcessDefinitionEntity>() {
public ProcessDefinitionEntity execute(CommandContext commandContext) {
return Context.getProcessEngineConfiguration()
.getDeploymentManager()
.findDeployedLatestProcessDefinitionByKey("myProcess");
}
});
</blockcode>
Best regards,
<blockcode>
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
ProcessDefinitionEntity processDefinitionEntity = commandExecutor.execute(new Command<ProcessDefinitionEntity>() {
public ProcessDefinitionEntity execute(CommandContext commandContext) {
return Context.getProcessEngineConfiguration()
.getDeploymentManager()
.findDeployedLatestProcessDefinitionByKey("myProcess");
}
});
</blockcode>
Best regards,
