title: HTTP Status 500 - failed to lazily initialize a collection of role: ..., could not initialize proxy - no Session
body: <p>I try query customer list as json from spring controller. when i access url i can get list no error. </p>
  
  <p>-CustomerController</p>
  
  <pre><code>@RequestMapping("getCustomerListRB")
  public @ResponseBody List&lt;Customer&gt; getCustomerListsRB() {
      List&lt;Customer&gt; cusList = new ArrayList&lt;Customer&gt;();
      cusList = cusService.getList();
      return cusList;
  }
  </code></pre>
  
  <p>but when i try join table in customer model
  -Customer.java</p>
  
  <pre><code>   @OneToMany(mappedBy = "Customer", cascade = CascadeType.ALL)
      private List&lt;MainOrder&gt; MainOrder;
  
      public List&lt;MainOrder&gt; getMainOrder() {
          return MainOrder;
      }
      public void setMainOrder(List&lt;MainOrder&gt; mainOrder) {
          MainOrder = mainOrder;
      }
  </code></pre>
  
  <p>run server again it have error like bellow:</p>
  
  <pre><code>org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: failed to lazily initialize a collection of role: com.mdr.model.Customer.mainOrders, could not initialize proxy - no Session (through reference chain: java.util.ArrayList[0]-&gt;com.mdr.model.Customer["mainOrders"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: failed to lazily initialize a collection of role: com.mdr.model.Customer.mainOrders, could not initialize proxy - no Session (through reference chain: java.util.ArrayList[0]-&gt;com.mdr.model.Customer["mainOrders"])
      org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.writeInternal(MappingJackson2HttpMessageConverter.java:256)
      org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:208)
      org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:143)
      org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:89)
      org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:193)
      org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:71)
      org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:122)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
      org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  </code></pre>
  
  <p>After i add fetch = FetchType.EAGER like below</p>
  
  <pre><code>@OneToMany(mappedBy = "Customer", cascade = CascadeType.ALL,fetch = FetchType.EAGER) 
  </code></pre>
  
  <p>I run server again it don't have error but can't get data. please help me !</p>