I thought that when you call Session#lock on a detached object that it reattaches it and allows you to access related objects that an earlier session had not initialized. But when I try to do this, I'm getting an exception. My code looks something like this:
Code:
SomeObject someObj = ...; // initialized in a session
// ... At this point, the session is closed, so the object is detached.
Session newSession = ...; // open a new session
newSession.lock(someObj, LockMode.NONE);
Object relatedObj = someObj.getRelatedObject();
Seems like this should work, but I'm getting a HibernateException: "Could not initialize proxy - the owning Session was closed". The call stack indicates it was thrown by the related object's proxy. What's the problem?
Using Hibernate 2.1.6.
Thanks!