I've seen several posts on this subject, but no difinitive answer. I have a class structure like:
Code:
AbstractObject*
__________|__________
| |
ConcreteSubA AbstractSubB*
___________|____________
| |
ConcreteSubC ConcreteSubD
* Abstract Class
I'm using table-per-class-heirarchy and it works fine. But to pull it off, I've been mapping the intermediate abstract class (AbstractSubA*) with a discriminator value of "-1" or some other artificial value.
While this seems to work, I can't help but feel that there must be a better way to do it. I also worry that at some point in the future I'll run into a query that won't work properly as a result of my mapping.
Is this the best way to handle this situation?
Here's a sample of my mapping documents:
Mapping documents:Code:
<class name="AbstractObjectA" table="obj">
<id name="id" type="long" column="ID">
<generator class="native"/>
</id>
<discriminator column="objType" type="integer"/>
...
<subclass name="ConcreteSubA" discriminator-value="1">
...
</subclass>
<subclass name="AbstractSubB" discriminator-value="-1">
...
</subclass>
<subclass name="ConcreteSubC" discriminator-value="2">
...
</subclass>
<subclass name="ConcreteSubD" discriminator-value="3">
...
</subclass>
</class>
Notice the discriminator value of -1 for the intermediary abstract class AbstractSubB. Is there a better way to handle this?