Hi,
I have a question about the Hibernate.initialize functionality.
I have struts application with Filter creating and closing the session for each request with the ThreadLocal pattern.
I have a object which has 2 lazy collections and 5 proxied properties.
session1 opens
I found 5 of this MAIN object in the db using criteria query.
session1 closes as view jsp has been rendered.
user click which object wants to edit
session2 opens
I reattach the object to the current session
session.lock(object, LockMode.NONE);
here I would like to initialize some of the properties which are proxies of the object calling the
Hibernate.initialize(object.getProperty1());
session2 closes
session3 opens
I want to access the object.getProperty1 and I got an LazyInitialization exception....
I'm little bit confused about this. this is a sentence from HIA ->
Hibernate.initialize(cat) will
force the initialization of a proxy, cat, as long as its Session is still open.
of course the session of the proxied property1 object is not open anymore.
but I CAN NOT call the initialize in the session1 where the object was loaded as I have a collection of them there and that would not make any sense.
is there an other way to force a proxy object to get initialized???
would this make any sense? >
session2.lock(object.getProperty1(), LockMode.NONE);
Hibernate.initialize(object.getProperty1());
or this would not work either?
am I doing something wrong here? (quiet likely :))
THanks for any help!
Istvan
Hibernate version:
3.1.2
|