如何从子对象引用以@MappedSuperclass注释的父对象?

时间:2019-06-13 09:16:09

标签: java hibernate jpa

如何将我的子对象引用为其父对象,并用@MappedSuperclass进行注释?这些是我的课程:

@MappedSuperclass
public class Person extends BaseEntity {}

@Entity
@Table(name = "employee", catalog = "enrollment_system", uniqueConstraints =
@UniqueConstraint(columnNames = {"reference", "emp_number"}))
public class Employee extends Person implements Serializable{}

@MappedSuperclass
public class BackGroundHistory extends BaseEntity {

    @ManyToOne
    @JoinColumn(name = "person_id")
    @ForeignKey(name = "fk_person_history")
    private Person person;

 }

@Entity
@Table(name = "educational_history", catalog = "enrollment_system")
public class EducationalHistory extends BackGroundHistory implements java.io.Serializable {}

在运行时,出现此错误:

Exception in thread "main" org.hibernate.AnnotationException: @OneToOne or @ManyToOne on entities.EducationalHistory.person references an unknown entity: entities.Person

我这样做是为了避免对BackGroundHistory类进行多次声明,因为除了Employee类之外,我还拥有Applicant类和Student类。

1 个答案:

答案 0 :(得分:0)

映射的超类不是实体,它仅用于扩展或继承ID , CREATE_TIME , UPDATE_TIME ..etc

之类的属性。
相关问题