I am using Spring with Hibernate to develop a portlet for the Liferay portal portal. Now I have basically two entities, A and B, where A possibly contains a lot of B. So this happens with the mapping between the two.
<set cascade="all" lazy="true" name="comments" order-by="creationDate desc">
<key column="lfpn_pinboardentries_idPinboardEntry" not-null="true"/>
<one-to-many class="Comment"/>
</set>
In the corresponding DAO of object A in the DAO layer, I inherit the "HibernateDaoSupport" provided by spring, and so a typical data lookup looks like this:
...
public A getA(long id) {
return (A) getHibernateTemplate().get(A.class, id);
}
...
Everything works fine if I have "lazy = false", but as soon as I switch to "lazy = true", it causes the following error:
org.hibernate.LazyInitializationException: failed to lazily initialize role collection: com.lifepin.entities.PinboardEntry.com, session or session closed
- , , ?
!