cancel
Showing results for 
Search instead for 
Did you mean: 

lazy loading outside command context exception

rohitagrawal
Champ on-the-rise
Champ on-the-rise
Hi,

I am creating a task entity and setting local variables at the same time and then saving it.
It gives me "lazy loading outside command context exception" exception.
I want to do it i a single DB call only.
Please suggest

Regards,
Rohit
3 REPLIES 3

jbarrez
Star Contributor
Star Contributor
Could you paste your code?

A solution to only have one  transaction it to write your own command, and hand it over to the ManagementService (executeCommand operartion)

rohitagrawal
Champ on-the-rise
Champ on-the-rise
TaskEntity myTask = new TaskEntity();
myTask.setName(str);
myTask.setOwner("GroupName");
myTask.setVariableLocal("test", "test21313");
taskService.saveTask(myTask);

trademak
Star Contributor
Star Contributor
You should use the following lines to do this:

<blockcode>
Task myTask = taskService.newTask();
myTask.setName(str);
myTask.setOwner("GroupName");
taskService.saveTask(myTask);
taskService.setVariableLocal(myTask.getId(), "test", "test21313");
</blockcode>

So use the newTask method and first save the task before trying to add a variable.

Best regards,