AnsweredAssumed Answered

Got lazy loading outside command context Exception when setting Task Object as a member of a class and return it to front-end.

Question asked by xiangwangcheng on Aug 7, 2016
Latest reply on Oct 16, 2016 by saysiva
I was trying to query task by process instance id and that worked well, and then I set the Task to my own java class(Ticket, the code is below), that worked well either. But all things went wrong where I returned my java class to front-end(JSP).

I got this Exception:

Could not write content: lazy loading outside command context (through reference chain: com.chinamobile.epic.base.common.Response["entity"]->
com.chinamobile.epic.nami.model.ComplaintTicket["task"]->
org.activiti.engine.impl.persistence.entity.TaskEntity["variableInstances"]);
nested exception is com.fasterxml.jackson.databind.JsonMappingException: lazy loading outside command context (through reference chain: com.chinamobile.epic.base.common.Response["entity"]->
com.chinamobile.epic.nami.model.ComplaintTicket["task"]->
org.activiti.engine.impl.persistence.entity.TaskEntity["variableInstances"])

I am using SpringMVC and  this is my controller:

   @RequestMapping(value = "/tickets/{ticketId}", method = RequestMethod.GET)
   public Response getTicketDetail(@PathVariable String ticketId) {
      Ticket ticket;
      ticket = baseTicketService.getDetailByTicketId(ticketId);

      return Response.success(ticket);
   }


and this is my Service:

public Ticket getDetailByTicketId(String ticket_id){
   
      String resultTicket = new Ticket();
           //set some other members here
      Task task = taskService.createTaskQuery().processInstanceId(resultTicket.getProcessInstanceId()).active()
            .singleResult();
      if (task != null) {
         resultTicket.setTask(task);
      }
   }


And this is the Ticket class:

   import org.activiti.engine.task.Task;
   public class Ticket {
   
      private Task task;
   
      //and there are some other members
   
   
      public void setTask(Task task) {
         this.task = task;
      }
      public void setTask(Task task) {
         this.task = task;
      }
   
   }


I do want to deliver the information of  Task to the front-end.
Is there some solutions for this Exception? I really appreciate it if someone can help me…
Thanks…

Outcomes