-->
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.  [ 1 post ] 
Author Message
 Post subject: Strange Behavoir in rememberig non existing objects
PostPosted: Fri Dec 10, 2004 2:40 am 
Newbie

Joined: Fri Aug 27, 2004 1:52 pm
Posts: 9
Hibernate version: 2.1

I discovered some strange behavior in the way that Hibernate remembers which objects don’t exist in the current session, related to joined-sub-classes. I’d like to hear if it is in fact a bug or if the behavior is by design.

Suppose you had a type hierarchy where B extends A and C extends A. Further suppose there was a persistant instance of B with an ID of 1234. If you try to get C first, using 1234 and you (rightly) failed to load the object, hibernate would remember that that object doesn’t exist for the entire A type hierarchy, not just for C. So you if then later tried to load B in the same session, it would report that the object doesn’t exist. Here is an example in code:

Code:
Session s = ….
C c = s.get(C.class, new Long(1234));   //c will correctly be null

B b = s.get(B.class, new Long(1234));   //b will incorrectly return as null as since hibernate has remembered that 1234 doesn’t exist for the entire A hierarchy.



Now one workaround for this is to always load the object as the uppermost persistent object in the type hierarchy if you are unsure if the object is in fact that type, but this leads to inefficient reading and potentially unnecessary creation of objects.

Is this behavior by design?


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

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.