Hi all,
Hibernate version:
3
Mapping documents:
I have a one to one association between class A and class B, the only direction for me is from A to B
Code between sessionFactory.openSession() and session.close():
Code:
try {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List aList = session.createQuery("from A").list();
session.getTransaction().commit();
String desc = ((A)aList.get(0)).getB().getDescription();
}
catch(Exception e) {HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().rollback();
}
Full stack trace of any exception that occurs:
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)
....
Name and version of the database you are using:
MySql 5
My object A has a method to retrieve its associated object B, that is getB()
I have noticed that if I access a property of an object B after session commit where I loaded all objects A, I have that above exception.
I have also noticed that, If I call also following statement:
List bList = session.createQuery("from B").list();
after loading of A objects, then I can access all properties of all related B objects.
What I would like to understand is if there are other clever methods to load an Object and all its related object, or If I have to load all objects inside a Session.
Thanks in advance,
best regards
Gamby