AnsweredAssumed Answered

variableListener did not set

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

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();


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


get called, and following exception occurs:

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

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:

JsonMapper mapper = new JsonMapper();
String result = mapper.toJson(processInstance);

the result is null where processInstance is not.

please help out
great thanks

Could not write JSON: lazy loading outside command context (through reference chain:["body"]->java.util.ArrayList[0]->["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:["body"]->java.util.ArrayList[0]->["processInstance"]->org.activiti.engine.impl.persistence.entity.ExecutionEntity["variableInstances"])