2.13.6.1. Single Table
The InheritanceType.SINGLE_TABLE strategy maps all classes in the hierarchy to the base class' table.
In our model, Subscription is mapped to the
CNTRCT.SUB table. LifetimeSubscription, which extends Subscription, adds its field data to this table as well.
Example 28. Single Table Mapping
@Entity
@Table(name="SUB", schema="CNTRCT")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public class Subscription {
...
}
@Entity(name="Lifetime")
public class LifetimeSubscription
extends Subscription {
...
}
The same metadata expressed in XML form:
<entity class="org.mag.subcribe.Subscription">
<table name="SUB" schema="CNTRCT"/>
<inheritance strategy="SINGLE_TABLE"/>
...
</entity>
<entity class="org.mag.subscribe.LifetimeSubscription">
...
</entity>
Single table inheritance is the default strategy.
Thus, we could omit the @Inheritance annotation in the example above and get the same result.
|
|
Mapping subclass state to the superclass table is often called flat inheritance mapping. |