2.13.6. Inheritance
In the 1990’s programmers coined the term impedance mismatch to describe the difficulties in bridging the object and relational worlds. Perhaps no feature of object modeling highlights the impedance mismatch better than inheritance. There is no natural, efficient way to represent an inheritance relationship in a relational database.
Luckily, JPA gives you a choice of inheritance strategies, making the best of a bad situation.
The base entity class defines the inheritance strategy for the hierarchy with the Inheritance annotation. Inheritance has the following properties:
-
InheritanceType strategy: Enum value declaring the inheritance strategy for the hierarchy. Defaults toInheritanceType.SINGLE_TABLE. We detail each of the available strategies below.
The corresponding XML element is inheritance, which has a single attribute:
-
strategy: One ofSINGLE_TABLE,JOINED, orTABLE_PER_CLASS.
The following sections describe JPA’s standard inheritance strategies.
|
|
OpenJPA allows you to vary your inheritance strategy for each class, rather than forcing a single strategy per inheritance hierarchy. See Additional JPA Mappings in the Reference Guide for details. |