Rule Definition
If you require polymorphic associations or queries, and subclasses declare many properties (subclasses differ mainly by the data they hold), lean toward the table-per-subclass approach.
Note that By default, choose table-per-class-hierarchy for simple problems. For more complex cases (or when you're overruled by a data modeler insisting upon the importance of nullability constraints), you should consider the table-per-subclass strategy. But at that point, ask yourself whether it might be better to remodel inheritance as delegation in the object model. Complex inheritance is often best avoided for all sorts of reasons unrelated to persistence or ORM.
Remediation
Use the table-per-subclass strategy to map the hierarchy.
Violation Code Sample
----> animal.hbm.xml
<class name="Animal" table="ANIMAL">
<id name="id" type="long" column="ANIMAL_ID">
<generator class="native"/>
</id>
<discriminator column="TYPE" type="string"/>
<property name="amount" column="AMOUNT"/>
// VIOLATION: one of the subclass attributes count
// is greater or equal to 3 and table-per-subclass
// strategy is not used
<subclass name="Dog" discriminator-value="DOG">
<property name="race" column="RACE"/>
</subclass>
<subclass name="Cat" discriminator-value="CAT">
<property name="color" column="COLOR"/>
<property name="country" column="COUNTRY"/>
<property name="age" column="AGE"/>
<property name="owner" column="OWNER">
</subclass>
</class>
Fixed Code Sample
<class name="Animal" table="ANIMAL">
<id name="id" type="long" column="ANIMAL_ID">
<generator class="native"/>
</id>
<property name="amount" column="AMOUNT"/>
// FIXED table-per-subclass strategy is used
<joined-subclass name="Dog" table="DOG">
<key column="DOG_ID"/>
<property name="race" column="RACE"/>
</joined-subclass>
<joined-subclass name="Cat" table="CAT">
<key column="CAT_ID"/>
<property name="color" column="COLOR"/>
<property name="country" column="COUNTRY"/>
<property name="age" column="AGE"/>
<property name="owner" column="OWNER">
</joined-subclass>
</class>
Reference
http://www.developer.com/open/print.php/10930_3559931_5
Hibernate in Action (ISBN 1932394-15-X) p 105
Related Technologies
JEE
Technical Criterion
Efficiency - SQL and Data Handling Performance
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.