Looking for bug in our program, I spotted something, which is either a bug in Hibernate or simply undocumented Feature. We are using Hibernate 2.1.7, jTDS and SQLServer.
First, there was a bug in our program, where a false id was provided to an internal method. This method called the Session.get() with the false id and the result was not what one might expect.
Well, actually it was our fault to provide a false id and we have already corrected this, but may be somebody is curious and can look into the following. Here is the (very simplified) scenario to reproduce it:
There are three classes, say A, B and C, where A is the root class, B is subclass of A, C is subclass of A (note: C is no subclass of B, also B is not subclass of C). All this three classes are saved in a single table using the mapping
<class name=”A” table=”atable” discriminator-value=”A”>
<id type="long" name="id" unsaved-value="0">
<generator class="foo.CommonHiLoGenerator"/>
</id>
<discriminator column="subclass" type="character"/>
<subclass name=”B” discriminator-value=”B”/>
<subclass name=”C” discriminator-value=”C”/>
</class>
Create at least one instance from each class, say A(id=1), B(id=2), C(id=3).
When calling Session.get(B.class, new Long(1)) with a false Id, I expected to get null or at least an exception from hibernate, because there is no instance of B with id=1. But the method simply returns a correct object for the given id – here A(id=1). I try it even with Session.get(B.class, new Long(3)) and I get the correct instance of C(id=3). Is this an issue, or is this simply a undocumented feature? Or am I blind and I wasn't able to find this documented (sorry if so)?
With best regards
Peter
|