Reputation: 11455
I have an inheritance hierarchy that is similar to the following
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
abstract BaseEntity //all persistable entity extends this
I want to employ a joined inheritance strategy for the following. With tables for Employee and Doctor. How do I go about doing this. Will @MappedSuperclass on Person work???
abstract Person extends BaseEntity
Employee extends Person
Doctor extends Person
Upvotes: 0
Views: 1705
Reputation: 692121
You're doing it backwards. Having an entity inheritance with BaseEntity is not something you want: you'll never have an association from one entity to a BaseEntity. BaseEntity should thus be either a regular class, without any annotation, or a MappedSuperclass if it has some mapping annotations.
On the contrary, there's a good chance you'll have some entity which has an association with other persons, without caring if they're doctors or employees. So an entity inheritance between persons, doctors or employees makes sense. If it's not the case, and every entity references either doctors or employees, then Person should also be a MappedSuperclass.
Upvotes: 2