Greetings, In my domain model,
'Family' has many 'SubFamily's 'SubFamily' has many 'Locus's
and relationships are bi-directional with lazy-loading.
ie. 'Locus' can access in parent 'SubFamily' using alocus.getSubFamily();
Down below snippet I have given the DAO method to retrieve a Locus .
In my webapplication (Wicket based)
I get locus from DAO and then try to get the SubFamily as:
Locus alocus = dao.getLocusByLocusId(alocusid);
SubFamily asubfamily=alocus.getSubFamily();
But it throws the error:
org.hibernate.LazyInitializationException: could not initialize proxy - no Session at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:57) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111) at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150) at com.bigg.nihonbare.common.domain.SubFamily$$EnhancerByCGLIB$$a0d68bed.getSubFamilyId(
Any tips?
public Locus getLocusByLocusId(final String LocusId) {
return (Locus) this.getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session) {
Criteria criteria = session.createCriteria(Locus.class);
criteria.add(Expression.eq("locusId", LocusId));
List result =criteria.list();
if (result!=null && result.size() > 0) {
return result.get(0);
}
return null;
}
});
}