Rule Definition
If you require polymorphic associations (an association to a superclass, hence to all classes in the hierarchy with dynamic resolution of the concrete class at runtime) or queries, and sub-classes declare relatively few properties (particularly if the main difference between subclasses is in their behavior), lean toward the table-per-class-hierarchy model.
Remediation
Use the table-per-class-hierarchy 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>
<property name="amount" column="AMOUNT"/>
// VIOLATION none of the subclass attributes count
// is greater or equal to 3 and
// table-per-class-hierarchy strategy is not 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"/>
</joined-subclass>
</class>
Fixed Code Sample
<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"/>
// FIXED: table-per-class-hierarchy strategy is used
<subclass name="Dog" discriminator-value="DOG">
<property name="race" column="RACE"/>
</subclass>
<subclass name="Cat" discriminator-value="CAT">
<property name="color" column="COLOR"/>
</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.