Hi, was under the impression this exceptions only happens when you have a Set/one-many relationship and when you try to load/get that List/Set ... But in my case am only trying to get a property of a class loaded by findById() ...
Code:
public T findById(ID id, boolean lock) {
T entity;
if (lock)
entity = (T) getSession().load(getPersistentClass(), id, LockMode.UPGRADE);
else
entity = (T) getSession().load(getPersistentClass(), id);
return entity;
}
getPersistentClass return a class initialized by getGenericSuperClass().getActualTypeArgument()[0] ....
Here's where i use findById
Code:
public Member findMemberDetails(String force, boolean lock)
{
Member mem = new Member();
try {
Transaction tx = session.beginTransaction();
tx.begin();
mem = daoInstance.findById(force, lock);
tx.commit();
}
catch (Exception ex) {
slf4j.debug("Failed to initialize Member details");
ex.printStackTrace();
}
return mem;
}
here's the code + exception
Code:
MemQualServiceImpl memServ = new MemQualServiceImpl ();
memServ.setHibernateSession( getSession() );
Member m = memServ.findMemberDetails("99035545", false);
slf4j.info ("Force No: " + m.getForce());
slf4j.info ("Name: " + m.getFullName());
slf4j.info ("Application Code: " + m.getAppCode());
// Exception ......
......
2009-07-14 15:07:51,921 [main] ERROR org.hibernate.LazyInitializationException - could not initialize proxy - no Session
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:86)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:140)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
at hibernate.model.Member_$$_javassist_0.getFullName(Member_$$_javassist_0.java)
at hibernate.apptest.HiberTester.init(HiberTester.java:62)
at hibernate.apptest.HiberTester.main(HiberTester.java:25)
2009-07-14 15:07:51,953 [main] INFO hibernate.apptest.HiberTester - ---- Exception occurred : org.hibernate.LazyInitializationException : could not initialize proxy - no Session
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:86)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:140)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
at hibernate.model.Member_$$_javassist_0.getFullName(Member_$$_javassist_0.java)
at hibernate.apptest.HiberTester.init(HiberTester.java:62)
at hibernate.apptest.HiberTester.main(HiberTester.java:25)