-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Strange lazy initialization problem: id is null
PostPosted: Thu Aug 11, 2005 10:12 am 
Beginner
Beginner

Joined: Mon Feb 23, 2004 5:11 pm
Posts: 39
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?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 10:42 am 
Beginner
Beginner

Joined: Mon Feb 23, 2004 5:11 pm
Posts: 39
The problem is actually worse than I initially thought:

the Id property is null even when the session is open. Whats more strange is, I could see all other proerties except for the id property.

My guess is this has some thing to do with the CGLIB enhancer class of my class.

Any pointers?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 10:48 am 
Beginner
Beginner

Joined: Mon Feb 23, 2004 5:11 pm
Posts: 39
Never mind. I figured out the problem. It had to do with the final methods (my get and set ID methods were).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.