title: Solution for JsonMappingException: lazily initialize a collection without using @Jsonignore
body: <p>I need to response JSON as output. But It shows the exception </p>
  
  <pre><code>org.codehaus.jackson.map.JsonMappingException: failed to lazily initialize a collection of role: com.sublime.np.entity.User.roles, could not initialize proxy - no Session (through reference chain: java.util.ArrayList[0]-&gt;com.sublime.np.entity.Question["user"]-&gt;com.sublime.np.entity.User["roles"])
      at org.codehaus.jackson.map.JsonMappingException.wrapWithPath(JsonMappingException.java:218)
      at org.codehaus.jackson.map.JsonMappingException.wrapWithPath(JsonMappingException.java:183)
      at org.codehaus.jackson.map.ser.std.SerializerBase.wrapAndThrow(SerializerBase.java:140)
      at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:158)
      at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
      at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
      at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
      at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
      at org.codehaus.jackson.map.ser.std.StdContainerSerializers$IndexedListSerializer.serializeContents(StdContainerSerializers.java:122)
      at org.codehaus.jackson.map.ser.std.StdContainerSerializers$IndexedListSerializer.serializeContents(StdContainerSerializers.java:71)
      at org.codehaus.jackson.map.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:86)
      at org.codehaus.jackson.map.ser.StdSerializerProvider._serializeValue(StdSerializerProvider.java:610)
      at org.codehaus.jackson.map.ser.StdSerializerProvider.serializeValue(StdSerializerProvider.java:256)
      at org.codehaus.jackson.map.ObjectMapper.writeValue(ObjectMapper.java:1613)
      at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.writeInternal(MappingJacksonHttpMessageConverter.java:209)
      at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:208)
      at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:143)
      at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:89)
      at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:193)
      at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:71)
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:122)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
      at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
  </code></pre>
  
  <p>I used so many relationship among the entities. 
  My Qustion entity looks like, </p>
  
  <pre><code>@Entity
  public class Question {
  
      @Id
      @GeneratedValue
      private Integer id;
  
      @Size(min=5, message = "Title must be at least 5 characters !" )
      private String title;
  
      @Size(min=20, message = "Description must be at least 20 characters !" )
      private String description;
  
      private int upVote;
  
      private int downVote;
  
      @Column(name = "published_date")
      private Date publishedDate;
  
      @ManyToOne
      @JoinColumn(name="user_id")
  
      private User user;
  
      @OneToMany(mappedBy="question", cascade=CascadeType.REMOVE)
      private List&lt;Answer&gt; answers;
  
      @OneToMany(mappedBy="question", cascade=CascadeType.REMOVE) 
      private List&lt;Comment&gt; comments;
  
      @ManyToOne
      @JoinColumn(name="tag_id")
      private Tag tag;
  </code></pre>
  
  <p>When i use @JsonIgnore  annotation, it works. But From my json field which are in relationship disappear. </p>
  
  <pre><code>@OneToMany(mappedBy="question", cascade=CascadeType.REMOVE)
      @JsonIgnore  
      private List&lt;Answer&gt; answers;
  
      @OneToMany(mappedBy="question", cascade=CascadeType.REMOVE)
      @JsonIgnore  
      private List&lt;Comment&gt; comments;
  
      @ManyToOne
      @JoinColumn(name="tag_id")
      @JsonIgnore  
      private Tag tag;
  </code></pre>
  
  <p>JSON after using @JsonIgnore, </p>
  
  <pre><code>[
    {
      "id": 1,
      "title": "ABC",
      "description": "ABC",
      "upVote": 0,
      "downVote": 0,
      "publishedDate": 1433436068000
    },
    {
      "id": 2,
      "title": "SQL Exception",
      "description": "ABC",
      "upVote": 0,
      "downVote": 0,
      "publishedDate": 1433436068000
    }
  ]
  </code></pre>
  
  <p>My Controller, </p>
  
  <pre><code>@RequestMapping(value = "getquestion", method = RequestMethod.GET)
      public @ResponseBody List&lt;Question&gt; getQuestion() {
          List&lt;Question&gt; questions = questionService.getAll();
          return questions;
  }
  </code></pre>
  
  <p>So, I need json with all the fields of entity. How can i get that ? any idea ?</p>