Annotation Interface Inheritance


@Target(TYPE) @Retention(RUNTIME) public @interface Inheritance
Specifies the inheritance mapping strategy for the entity class hierarchy which descends from the annotated entity class. The inheritance strategy for the whole entity class hierarchy is determined by the mapping of the root class of the hierarchy.

There are three basic strategies which may be used when mapping an entity class hierarchy to tables in a relational database:

  • With a single table per class hierarchy, every field declared by any class in the hierarchy maps to a column of the same table. A subclass shares the table of its superclasses.
  • With a table per concrete entity class, every field declared or inherited by a given subclass is mapped to the same table, but each concrete class in the hierarchy has its own separate table
  • For the joined subclass strategy, any field which is declared by a subclass is mapped to a separate table from the fields which are declared by its superclass. Joins may be used to retrieve all fields declared and inherited by the subclass.

This annotation must be applied to the entity class that is the root of the entity class hierarchy. If the Inheritance annotation is not specified, or if no inheritance type is specified for an entity class hierarchy, the SINGLE_TABLE mapping strategy is used.

Example:

@Entity
@Inheritance(strategy = JOINED)
public class Customer { ... }

@Entity
public class ValuedCustomer extends Customer { ... }
Since:
1.0
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The inheritance mapping strategy for the entity inheritance hierarchy.
  • Element Details

    • strategy

      InheritanceType strategy
      The inheritance mapping strategy for the entity inheritance hierarchy.
      Default:
      SINGLE_TABLE