Hibernate继承,在两个不同的表中重复ID

时间:2018-10-15 16:15:22

标签: java hibernate jpa

@Entity
@Table(name = "parent");
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
    public class Parent {

    @Id
    @SequenceGenerator(name = "ME_SEQ", sequenceName = "ME_SEQ", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ME_SEQ")
    @Column(name = "PARENT_ID", columnDefinition = "NUMBER(38,0)", nullable = false, unique = true)
    private Long id;
}

还有一个子实体(单独的表),它具有指向父ID的PK和FK

@Entity
@Table(name = "child")
public class Child extends Parent {

    @Id
    @Column(name = "PARENT_ID")
    private Long id;
}

即使有两个分开的表,我也会从Hibernate中得到一个错误:

  

org.hibernate.mapping.UnionSubclass无法转换为   org.hibernate.mapping.RootClass

即使子类与父类的表不同,子类中是否也没有ID?

0 个答案:

没有答案