如何将我的子对象引用为其父对象,并用@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
类。
答案 0 :(得分:0)
映射的超类不是实体,它仅用于扩展或继承ID , CREATE_TIME , UPDATE_TIME ..etc