我尝试使用Hibernate。一切都很好,但是当我想要注释子类时,我遇到了问题。我希望每个表ID和FK(id)都来自子类
@Entity
@javax.persistence.Table(name="person")
@Inheritance(strategy=InheritanceType.JOINED)
public class Person{
@Id
@GeneratedValue
@Column(name="id_person")
protected int id_person;
@Column(name="name")
protected String name; ....
子类
@Entity
@javax.persistence.Table(name="worker")
@Inheritance(strategy=InheritanceType.JOINED)
@PrimaryKeyJoinColumn(name="id_person")
public class Worker extends Person {
@Id
@GeneratedValue
@Column(name="id_worker")
protected int id_worker;
@Column(name="salary")
protected int salary ; ...
我想拥有来自worker的唯一ID,因为这个类
@Entity
@javax.persistence.Table(name="driver")
@PrimaryKeyJoinColumn(name="id_worker")
public class Driver extends Worker{
@Id
@GeneratedValue
@Column(name="id_driver")
protected int id_driver;
@Column(name="category")
protected String category; ....
当我保存一个驱动程序以获取桌上人员的新ID时,怎么可能
工作人员的新ID以及来自该工作人员的ID,
驱动程序中的新ID和表驱动程序中该工作程序的ID ...?
在这种情况下,我收到错误org.hibernate.mapping.JoinedSubclass cannot be cast to org.hibernate.mapping.RootClass
,但是如果我从子类移动ID,那么我就不会获得该类的ID ...