gpt4 book ai didi

java - 如何从子对象引用带有@MappedSuperclass注释的父对象?

转载 作者:行者123 更新时间:2023-12-02 04:32:01 26 4
gpt4 key购买 nike

我如何将我的子对象引用到用@MappedSuperclass注释的父对象?这些是我的类(class):

@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 {}

在运行时,我收到此错误:

线程“main”org.hibernate.AnnotationException中的异常:entities.EducationalHistory.person上的@OneToOne或@ManyToOne引用了未知实体:entities.Person

我这样做是为了避免在 BackGroundHistory 类上进行多次声明,因为除了 Employee 类之外,我还有类 Applicant 和类 学生

最佳答案

映射的父类(super class)不是实体,它只是用于扩展或继承属性,例如 ID 、 CREATE_TIME 、 UPDATE_TIME ..etc

关于java - 如何从子对象引用带有@MappedSuperclass注释的父对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56577213/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com