-->
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.  [ 2 posts ] 
Author Message
 Post subject: question about polymorphic query behavior
PostPosted: Thu Oct 28, 2004 12:56 pm 
Newbie

Joined: Thu Sep 09, 2004 7:55 pm
Posts: 8
Hibernate version:
2.1.6

hi all,

i'm new to hibernate and have a question about the behavior of polymorphic queries using Session.get(class, serializable). i'm using the table per class hierarchy model. i've found, by mistake, something that i think shouldn't work, but does.

here's the scenario. i have three classes, {A, B, C}, for which A is abstract and B & C are concrete subtypes of A with discrimator values of {'B', 'C'} respectfully. i have seeded the data base with some fixture data, including both 'B's and 'C's, to test the query behavior. to keep things simply assume the following rows:

ID NAME DISCRIMATOR
1 'one' 'B'
2 'two' 'C'
3 'three' 'B'

here's where i get confused. i use Session.get(C.class, new Integer(1)) and the session returns an instance of C even though the discrimator clearly specifies this row should be an instance of 'B'. i was expecting to get an exception that the class specified to Session.get was not of the correct type based on the discriminator value read into the resultset. i stepped though the code in a debugger to understand what hibernate was doing, thinking the problem was my own.

what i found out was that, at least in this case, the discrimator is never used during this operation. i was epecting the EntityPersister to do a type check, either using the discrimatorSqlValue in the where clause of its sqlConcreteSelectString or even to perform a String.equals comparison between the resultset discrimator column value and the persisters own discrimatorSqlValue property.

if could someone shed some light on this for me it would be greatly appreciated? in addition i suppose that this same problem would not be observed if i used the table per subclass strategy since the join condition will ensure that the result is of the expected by.

tia,
sean


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 01, 2004 9:46 am 
Newbie

Joined: Thu Sep 09, 2004 7:55 pm
Posts: 8
anyone?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.