I have created database tables using the inheritance mapping. I want all tables to have audit columns.
Here is the code:
- An abstract Auditable class
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class Auditable {
@CreatedDate
private LocalDateTime createdAt;
@CreatedBy
private String createdBy;
}
- a Person class:
@Entity
@Table(name = "person")
@Inheritance(strategy = InheritanceType.JOINED)
public class Person extends Auditable {
private String name;
}
- a Student class:
@Entity
@PrimaryKeyJoinColumn(name = "person_id")
public class Student extends Person {
private int grade;
}
- and a Staff class:
@Entity
@PrimaryKeyJoinColumn(name = "person_id")
public class Staff extends Person {
private int salary;
}
My problem is only the created_at and created_by of the Person table are generated, but the created_at and created_by of Staff and Student tables are null.
Is it possible to have the created_at and created_by of the Staff and Student tables generated too?