java - Hibernate继承,两个不同表中的重复ID
问题描述
@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;
}
还有一个子实体(单独的表),它有一个指向 Parent 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,即使它与父类是不同的表?
解决方案
推荐阅读
- excel - 如何将文件夹中的多个源工作簿中的数据复制到另一个工作簿,然后另存为新工作簿
- python - 如何使用 Flask 网络服务器对 Spotipy 进行身份验证?
- java - 以 10 秒为间隔运行 10 次函数的最佳方法
- python - 在 Numpy Python 中从 csv 文件读取数组时出错
- python - 从没有 UDF 的案例表达式中生成 spark 返回元组(StructType)
- laravel - 帮助的成员总数
- android - Flutter 如何从多图像选择器中保存图像
- java - 使用 Java 和 Mysql 验证 Android
- c - 对函数指针进行类型化似乎只对一个头文件是本地的
- javascript - 我们可以在 Web Speech API 中创建多个语音识别对象吗?