Inheriting mapping annotations

I'm working on a JPA project in which I have some different Entities extending a super-class annotated as Entity:

@Table(name = "export_profiles")
    @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.


If the sole purpose of your superclass is to define common mappings for the sub classes, but is not persistent itself, you would be better off using the @MappedSuperclass annotation or the <mapped-superclass> for xml mappings. There is an example here.

This case may be a good start in Postgres.

By example

CREATE TABLE "public"."abstract_export_profile" (
"label" TEXT

CREATE TABLE "public"."persistent_export_profile" (
"value" TEXT, 
CONSTRAINT "mandant_pkey" PRIMARY KEY("id")
) INHERITS ("public"."abstract_export_profile")

The Name Class:

public class AbstractExportProfile { ... }

And the

@Table(name= "mandant")
public class PersistentExportProfile extends AbstractExportProfile { ... }

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 @DiscriminatorValue to define the value of the DiscriminatorColumn.

Need Your Help

Using SELECT resultset to run UPDATE query with MySQL Stored Procedures

sql mysql stored-procedures resultset

I'm trying to understand MySQL Stored Procedures, I want to check if a users login credentials are valid and if so, update the users online status: