I noticed something a bit strange with hibernate today. I have a class hierarchy mapped to a single table using subclass mappings with discriminators. It seems that two of my subclasses inadvertently have the same discriminator value.
Off-hand I would have expected hibernate to complain about this on startup, when reading the mapping file, but it doesn't. It lets me persist both classes and writes the same discriminator in for instances of both classes. When I attempt to load these objects it always seems to instantiate instances of the last class to declare the duplicated discriminator value.
i.e. in Foo.hbm.xml there are subclass entries like:
<subclass name="ABC" discriminator-value="123"/>
<subclass name="DEF" discriminator-value="123"/>
Instances loaded from Foo are always of type DEF. Re-ordering the above two lines so that ABC appears last causes loaded instances to always be of type ABC.
Would it not make sense to detect cases of duplicated discriminators and fail to load mapping files containing them?
(this happens with hibernate 2.1.7)
Cheers,
Derek
|