我有 2 个表,对应 2 个类
class temp{
@Id
int x;
String name;
}
class perm{
@Id
int x;
String name;
}
假设 temp_customer 和 perm_customer
两者相同
我想将记录从 temp_customer 插入到 perm_customer。
但是使用 hibernate 执行此操作会在 perm_customer 中生成一个新 id 并复制所有其他记录。我也希望 perm_customer 中的 temp_customer 具有相同的 id。
最佳答案
perm表将有自己的主键并添加与temp的外键关系。 下面是 temp 和 perm 的表结构
class temp{
@Id
int x;
String name;
}
class perm{
@Id
int y;
@OneToOne
@JoinColumn(name="x")
temp t;
String name;
}
关于java - 在两个不同但相同的表中插入记录,Hibernate?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25967776/