我正在使用Hibernate JPA.
假设我有这些类:
AbstractPerson
|--> ConcreteEmployee
|--> ConcreteCustomer
Run Code Online (Sandbox Code Playgroud)
有没有办法让具体类具有独立的ID?
我正在使用InheritanceType.TABLE_PER_CLASS.
我有这些实体;
Person.class
@Entity
@Table(name = "person")
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class Person implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "person_id")
private long personID;
Run Code Online (Sandbox Code Playgroud)
StudentBean.class
@Entity
@Table(name = "student_information")
public class StudentBean extends Person {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long studentID;
Run Code Online (Sandbox Code Playgroud)
我的目标是将学生记录与Person类和StudentBean类中的详细信息一起保存在1个表中,但是我遇到了这些异常
org.hibernate.mapping.JoinedSubclass无法强制转换为org.hibernate.mapping.RootClass
在我的研究中我偶然发现了这个线程[Spring 3.1 Hibernate 4的继承异常无法转换为org.hibernate.mapping.RootClass
基于此,异常的原因是由于Parent和Child类中的@Id.但是如果我在我的任何一个类中删除了@Id,它将不允许我保存该对象,因为我没有我的实体的标识符.
我想要一个人员ID来识别学校外的人和学生证来识别学校里面的人,这可能吗?如果没有,我怎么能删除Person类的PK,但我仍然可以扩展它并将其保存到另一个表中.
最后,实现这个设计的最佳方式是什么,Person可以扩展为Student Class,Teacher Class,SchoolPrincipal Class