AnsweredAssumed Answered

variableListener did not set

Question asked by edword_0516@hotmail.com on Apr 19, 2016
Latest reply on Apr 25, 2016 by edword_0516@hotmail.com
i m just trying to do a simple data fetch and Object -> Json bothered me for days,  here is the code:

[java]
Task task = taskService.createTaskQuery().taskCandidateOrAssigned(userId).singleResult();
           
Repair repair =  ObjectUtil.mapToObject(runtimeService.getVariables(task.getProcessInstanceId()), Repair.class);
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).includeProcessVariables().active().singleResult();

repair.setProcessInstance(processInstance);
[/java]

everything is okay up until here, however, when i try to convert the Object repair to JSON format(in order to show data in front end), the method

[java]
VariableScopeImpl.ensureVariableInstancesInitialized()
[/java]

get called, and following exception occurs:

[java]
CommandContext commandContext = Context.getCommandContext();
if(commandContext == null) {
        throw new ActivitiException("lazy loading outside command context");
}
[/java]

it is weird because when the taskQuery and processQuery get executed, this method also gets called, but did not hit this exception, and when it tries to convert to JSON format, this exception gets throw.

looks like the task.variableInstance or process.variableInstance never gets initialized

even if i do something real simple:

[java]
JsonMapper mapper = new JsonMapper();
String result = mapper.toJson(processInstance);
[/java]

the result is null where processInstance is not.

please help out
great thanks

ERROR MSG:
Could not write JSON: lazy loading outside command context (through reference chain: cn.dantin.cloud.common.util.Response["body"]->java.util.ArrayList[0]->cn.dantin.cloud.application.repair.model.Repair["processInstance"]->org.activiti.engine.impl.persistence.entity.ExecutionEntity["variableInstances"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: lazy loading outside command context (through reference chain: cn.dantin.cloud.common.util.Response["body"]->java.util.ArrayList[0]->cn.dantin.cloud.application.repair.model.Repair["processInstance"]->org.activiti.engine.impl.persistence.entity.ExecutionEntity["variableInstances"])

Outcomes