Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
Hibernate 3.0.5
Consider the following 2 classes:
Class A - lazy=true by default
Class B - lazy=true by default
Class B has a many-to-one association with classA (lazy=true on the association as well).
Now in a new session, if I read in class A using
session.get(), the fully initialized object is loaded (as expected).
I could access its properties even after calling session.close().
Now in a another new session:
If I read in classB using session.get(), all classB properties are initialized
and the related classA is lazily loaded (as expected).
Then, in the same session, I also read in the associted classA object by directly calling session.get(). At this point I expect the object to be fully initialized.
Now I close the session. When i try to read the id property from the now detached classA object,
i get null (just null, no lazy initialization exception).
Before closing the session, I even tried initializing the classA object by calling Hibernate.initialize(). Id property is still null after the session is closed().
As I explained at the begining, this doesnt happen when I load the object directly in a new session. It only happens when the object is first read in as an associated class to classB. (i use session.get in all cases)
Note: when I make the lazy= false in the m-to-o association, the subsequent session.get(), initializes the object fully. But I dont want to change the mapping, I just want the associated object to fully initialized when i read it thro' session.get().
What am I missing?