title: Hibernate: lazy-loading doesn't work on one-to-many mapping on set
body: <p>I'm using Spring together with Hibernate for developing a Portlet for the Liferay portal server. I now have basically two entities, A and B, where A possibly contains many B's. So this goes to a one-to-many mapping between the two.</p>
  
  <pre><code>&lt;set cascade="all" lazy="true" name="comments" order-by="creationDate desc"&gt;
     &lt;key column="lfpn_pinboardentries_idPinboardEntry" not-null="true"/&gt;
     &lt;one-to-many class="Comment"/&gt;
  &lt;/set&gt;
  </code></pre>
  
  <p>In the corresponding DAO of entity A in the DAO layer, I'm inheriting from "HibernateDaoSupport" provided by spring, and so a typical retrieval of data looks like the following:</p>
  
  <pre><code>...
  public A getA(long id) {
    return (A) getHibernateTemplate().get(A.class, id);
  }
  ...
  </code></pre>
  
  <p>Everything works fine if I'm having "lazy=false", but as soon as I'm switching to "lazy=true" it gives me the following error:</p>
  
  <p><em>org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.lifepin.entities.PinboardEntry.comments, no session or session was closed</em></p>
  
  <p>Does anyone have a suggestion what could be the problem or hints how to solve it?</p>
  
  <p>Thanks!</p>