Suppose I have a Post
class which has a PostComment
collection, and that I load Post. PostComment has lazy="true" set, so PostComment is now represented by an Hibernate Proxy.
If I load Post
in a session, let's call it session1
, and then I close session1 before accessing PostComment, how can I access PostComment from a second session opened later?
I tried to access PostComment from session2 but got LazyInizializationException, I believed that to enable lazy loading it was enough to have a session opened, not the same session which loaded the parent object.
Should I use session2.update() to attach the objects to session2? Are there other methods other than using the same session in the whole process?