When an entity is inherited, you can specify the method of mapping the class hierarchy to a table as the inheritance mapping strategy. You specify the inheritance mapping strategy by using @Inheritance or the inheritance tag of the entity tag in the O/R mapping file.
There are three types of inheritance mapping strategies:
However, with Cosminexus JPA Provider, the TABLE PER CLASS strategy is not available. If the TABLE PER CLASS strategy is used when Cosminexus JPA Provider is used, an exception occurs when the application starts.
These strategies are specified in the value of the enumeration type javax.persistence.DiscriminatorType. The following points describe each strategy:
The SINGLE TABLE strategy is a strategy method of mapping all the classes present in the inheritance hierarchy of the entity class to one table. Therefore, the table must have an identification column as the column for identifying the class.
Specify the identification column in @DiscriminatorColumn or in the O/R mapping file. The default identification column name is DTYPE. If an identification column does not exist in the database, an exception occurs during the execution of the application.
If you want to specify the value stored in the identification column, use @DiscriminatorValue or the discriminator-value tag beneath the entity tag of the O/R mapping file.
The JOINED strategy is a strategy method of mapping the top-level of the class hierarchy to a single table. Each subclass is indicated by the subclass-specific fields that are not inherited from the superclass and by different tables with the primary key string that functions as the external key of the primary key for the superclass table.
In the case of the JOINED strategy, like in the case of the SINGLE TABLE strategy, the table to which the superclass is mapped must have an identification column.