gpt4 book ai didi

java - 在两个不同但相同的表中插入记录,Hibernate?

转载 作者:行者123 更新时间:2023-11-29 23:45:39 26 4
gpt4 key购买 nike

我有 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com