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
|