title: Hibernate and Jackson lazy serialization
body: <p>I'm working on a project using Hibernate and Jackson to serialize my objects.
  I think I understand how it is suposed to work but I can't manage to make it works.</p>
  
  <p>If I understand well, as soon as a relation fetch mode is set to LAZY, if you want this relation, you have to initialize it.</p>
  
  <p>Here is my class :</p>
  
  <pre><code>@Entity
  @JsonIgnoreProperties(ignoreUnknown = true)
  @Table(schema="MDDI_ADMIN", name = "MINIUSINE")
  @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
  public class MiniUsine {
  
      @Id
      @Column(name="MINIUSINEID", nullable = false)
      private int miniUsineID;
  
      @Column(name = "NAME", length = 40, nullable = false)
      private String name;
  
      @OneToMany(cascade = CascadeType.ALL)
      @JoinColumn(name="FluxID")
      @JsonInclude(JsonInclude.Include.NON_EMPTY)
      private Set&lt;Flux&gt; fluxs = new HashSet&lt;Flux&gt;();
  </code></pre>
  
  <p>And all getters and setters.</p>
  
  <p>I've also tried this <code>JsonInclude.Include.NON_EMPTY</code> as class annotation. Also tried the NON_NULL.
  However, jackson keeps sending me </p>
  
  <p><code>com.fasterxml.jackson.databind.JsonMappingException: failed to lazily initialize a collection of role: MiniUsine.fluxs, no session or session was closed (through reference chain: java.util.ArrayList[0]-&gt;MiniUsine["fluxs"])</code></p>
  
  <p>I'm serializing it with : <code>mapper.writeValueAsString(optMU);</code></p>
  
  <p>Using Jackson 2.3.2</p>
  
  <p>Thanks for help</p>