I have a domain object that has an attribute, which is a collection containing another domain object. This is done using sleep mode matching (which ultimately performs the join in another table). Hibernate, by default, seems to lazily instantiate this collection. This turns out to be wonderful, because, depending on what I need to display, I do not always need the collection that needs to be downloaded.
My problem is this: when writing my sleep requests (in my DAOs), I use the following to open / close a session:
Session session = getSessionFactory().openSession();
session.close();
The problem is that when Hibernate finally arrives at the lazy loading of my collection, it Sessionhas long been closed! How can I get around this? I guess I need to close the session as I do ...
This is the error I get:
SEVERE: failed to lazily initialize a collection of ...
source
share