cancel
Showing results for 
Search instead for 
Did you mean: 

lazy loading outside command context

gokceng1
Champ in-the-making
Champ in-the-making
Hello,
I've faced an exception, the one stated in topic.
I've been working on same code for a week. I've updated the code outside the activity related things but as a result I'm having this problem.

The code is like that:


public Data getDataFromExecutionId(String executionId) {
   ExecutionEntity executionEntity = (ExecutionEntity) getRuntimeService().createExecutionQuery().executionId(executionId).singleResult(); //this returns a process instance

   if (executionEntity == null) {
      return null;
   }
   String orderDataPlaceholderName = getPropertySourcesPlaceHolderConfigurer().resolvePlaceholder(VariableNameConstants.ORDER_DATA_EXP_NAME);
   Data data = (Data) executionEntity.getVariable(orderDataPlaceholderName); //this line throws "lazy loading outside command context"
}


org.activiti.engine.ActivitiException: lazy loading outside command context
   at org.activiti.engine.impl.persistence.entity.VariableScopeImpl.ensureVariableInstancesInitialized(VariableScopeImpl.java:58)
   at org.activiti.engine.impl.persistence.entity.VariableScopeImpl.getVariable(VariableScopeImpl.java:84)
   at …SimpleProcessManager.getDataFromExecutionId(SimpleProcessManager.java:77)

What can be the cause of this?

Thanks…
4 REPLIES 4

trademak
Star Contributor
Star Contributor
You should use the Activiti Service API to access the variable data or setup a command context yourself. So the easiest approach would be to get the variable data through the RuntimeService API.

Best regards,

gokceng1
Champ in-the-making
Champ in-the-making
Hi Tijs,
Thank you but how can I get variable through RuntimeService API? As far as I know, HistoryService API is responsible for that. I couldn't get it sorry.

jbarrez
Star Contributor
Star Contributor
RuntimeService.getVariableXX methods? That only applies when the process is still running.
Once the process instance is ended, you need to use the historyService. Also make sure that your history level is on a high enough level that the process variables are captured (default history level captures them).

gokceng1
Champ in-the-making
Champ in-the-making
My bad, sorry. I've only looked RuntimeService.createXXQuery methods. I'll give it a try and let you know.