Next Previous Index

10. Joined Subclass


Definition:

Joined subclasses are those that are mapped to a table-per-subclass design rather than a table-per-hierarchy.


Scenario:

We have one first-rank class, Foo, and another first-rank class, Bar, which is a subclass of Foo.


public class Bar extends Foo // Bar is a subclass of Foo

Hibernate Mapping:

In Hibernate, this could be mapped as follows:


<class name="Foo" table="foo">
    ...
    <property name="name" column="name" type="string"
    <joined-subclass name="subclass.Bar" table="bar">
         <key column="foo_id"/>
         <property name="age" column="age" type="string"/>
    </joined-subclass>
</class>

Table Schema:

Foo

id

name

Bar

foo_id

age


Here Bar inherits from Foo and so is joined using the PK foo_id and adds the extra data column age.


Bidirectionality:

Inheritance relationships are only unidirectional in Java. A child can determine its parent class but the reverse has no meaning.



Next Previous Index