Andrea Scarafoni
Andrea Scarafoni

Reputation: 955

JPA tables inheritance and object mapping

Is it possible to map a baseTable with a base class and tell to JPA tool to not insert in the class the fileds that are in the baseTable?

I have the field creation-date which i want in every table of my db, so i created a baseTable with that field and the other tables extend this baseTable.

When i generate the classe for mapping this structure, japtool creates for me each table with creation-date field, which clearly i'd want just in baseEntity class and not in every child class.

There is a way to accomplish it?

Upvotes: 0

Views: 58

Answers (1)

Andre Brito
Andre Brito

Reputation: 146

If I understood your answer correctly, I think you are looking for JPA Inheritance

@MappedSuperclass
public class BaseEntity {
@Id
    protected Integer id;
    protected Date createdDate;
    ...
}
@Entity
public class EntityA extends BaseEntity {
   protected String otherAttribs;
   ...
}
@Entity
public class EntityB extends BaseEntity {
   protected Float differentAttribs ;
   ...
}

Upvotes: 3

Related Questions