title: Java EE 6 + Hibernate Lazy load exception
body: <p>Here's where I'm stuck:</p>
  
  <blockquote>
    <p>javax.servlet.ServletException:
    org.hibernate.LazyInitializationException: failed to lazily initialize
    a collection of role: it.trew.model.TipoCaratteristica.traduzioni, no
    session or session was closed</p>
  </blockquote>
  
  <p>Some of my entities code:</p>
  
  <pre><code>@Entity
  @Table(name = "tipi_caratteristiche")
  public class TipoCaratteristica implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "id")
      private Long id;
  
      private String nome;
  
      @OneToMany(cascade = CascadeType.ALL)
      @JoinTable(
          name = "tipi_caratteristiche_traduzioni", 
          joinColumns = { @JoinColumn(name = "tipo_caratteristica_id") }, 
          inverseJoinColumns = { @JoinColumn(name = "traduzione_id") }
      )
      private List&lt;Traduzione&gt; traduzioni = new ArrayList&lt;Traduzione&gt;();
  </code></pre>
  
  <p>"Traduzione" is a simple plain entity with a pair of String properties.</p>
  
  <p>I have an "edit" jsf page which loads a "TipoCaratteristica" by id and try to show its List in a  tag.</p>
  
  <p>I use an ejb-facade method for fetching the edited object:</p>
  
  <pre><code>public T find(Object id) {
          return getEntityManager().find(entityClass, id);
      }
  </code></pre>
  
  <p>Then, in the jsf backing bean:</p>
  
  <pre><code>TipoCaratteristica tc = ejbFacade.find(Long.valueOf(value));
  </code></pre>
  
  <p>I read something about that exception. Actually, setting fetch type EAGER on the "traduzioni" collection fix it but I don't want to.
  I read about doing all in a transaction, or using Hibernate.initialize() but don't know how to do that.</p>
  
  <p>Can you help me please?</p>