I am trying to load a lazily initialized collection. Sometimes (it is hard to tell because there is a wrapper handling hibernate stuff) the session associated with the object is closed and I get a LazyInitializationException.
I can fix this by calling
session.lock(item, LockMode.NONE);
and the collection works.
When try the acces the collection, catch the exception and reassociate all is well. However causing an exception and fixing the problem bothers me. I should be able to do something like this
if(objectIsNotAssociatedWithSession(session,item))
session.lock(item, LockMode.NONE);
The problem is I don't know how to test whether an object is associated with a session - hopefully without havine to cause an exception.
How do I do this???
|