I've still got a problem with a lazy initialization which I couldn't solve with the help of other topics on this subject.
In my mapping file I've got a simple set-element:
Code:
<set name="groupTypes" >
<key update="false">
<column name="bp_cd"/>
<column name="bp_ods_cd"/>
<column name="cust_nb"/>
</key>
<one-to-many class="CustomerGroupType" />
</set>
In my DAO-class I've got the following search:
Code:
Session sess = getHibernateTemplate().getSessionFactory().getCurrentSession();
Criteria crit = sess.createCriteria(CustomerAddress.class)
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
.setFetchMode("groupTypes", FetchMode.JOIN)
.createAlias("groupTypes", "groupTypes")
.createAlias("groupTypes.details", "groupTypeDetails")
.add(Expression.eq("BpCd", customer.getBpCd()))
.add(Expression.eq("BpOdsCd", customer.getBpOdsCd()))
.add(Expression.eq("AddrTyCd", "002"))
.addOrder(Order.asc("CustNm"));
.........
List result = crit.list();
Unfortunately I got the error "failed to lazily initialize a collection of role".
I think it's just an understanding problem, but can someone please help me?
The error occurs if I try to get access to groupTypes in my Action-class:
Code:
for (Iterator iter = list.iterator(); iter.hasNext();)
{
CustomerAddress e = (CustomerAddress) iter.next();
e.getGroupTypes() ........
}
JasDA