I’m working on a JPA project in which I have some different Entities extending a super-class annotated as Entity:
@Entity
@Table(name = "export_profiles")
@NamedQueries({
@NamedQuery(name = "ExportProfile.getAll", query = "select ep from PersistentExportProfile ep"),
@NamedQuery(name = "ExportProfile.getByName", query = "select ep from PersistentExportProfile ep where ep.profileName = :name") })
public abstract class PersistentExportProfile extends AbstractExportProfile {
// other mappings...
}
I’d like to inherit mappings defined in my PersistentExportProfile into each sub-class.
Is it possible? What do I have to change in my super-class, and what do I have to add in my sub-entities?
NOTE all the sub-classes will be mapped on the same table.
The best solution for me was to add
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)and@DiscriminatorColumn(name="export_type", discriminatorType=DiscriminatorType.STRING)to my abstract class, then in my concrete classes I added@DiscriminatorValueto define the value of theDiscriminatorColumn.