3.2.4.4. Inherit properties from superclasses
This is sometimes useful to share common properties through a technical or a business superclass without including it as a regular mapped entity (ie no specific table for this entity). For that purpose you can map them as
@MappedSuperclass.
In database, this hierarchy will be represented as an
Order table having the id, lastUpdate and lastUpdater columns. The embedded superclass property mappings are copied into their entity subclasses. Remember that the embeddable superclass is not the root of the hierarchy though.
Note
Properties from superclasses not mapped as
@MappedSuperclass are ignored.
Note
The access type (field or methods), is inherited from the root entity, unless you use the Hibernate annotation
@AccessType
Note
The same notion can be applied to
@Embeddable objects to persist properties from their superclasses. You also need to use @MappedSuperclass to do that (this should not be considered as a standard EJB3 feature though)
Note
It is allowed to mark a class as
@MappedSuperclass in the middle of the mapped inheritance hierarchy.
Note
Any class in the hierarchy non annotated with
@MappedSuperclass nor @Entity will be ignored.
You can override columns defined in entity superclasses at the root entity level using the
@AttributeOverride annotation.
The
altitude property will be persisted in an fld_altitude column of table Plane and the propulsion association will be materialized in a fld_propulsion_fk foreign key column.
You can define
@AttributeOverride(s) and @AssociationOverride(s) on @Entity classes, @MappedSuperclass classes and properties pointing to an @Embeddable object.