Hibernate (JPA) inheritance mapping of abstract super classes
Use:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
AbstractLegalEntity
In the database you will have one table for AbstractLegalEntity
, and tables for classes, which extend AbstractLegalEntity
class. You won't have instances of AbstractLegalEntity
if it's abstract. Polymorphism can be used here.
When you use:
@MappedSuperclass
AbstractLegalEntity
@Entity
ConcretePersonEntity extends AbstractLegalEntity
This will create only one table in your database called ConcretePersonEntity
, containing columns from both classes.
Add @Entity
annotation to AbstractLegalEntity
. Instance of AbstractLegalEntity
will never exist - hibernate will load appropriate extending instances - ConcreteBusinessEntity
or ConcretePersonEntity
according to Id field.