【发布时间】:2021-09-07 13:55:04
【问题描述】:
我有两节课
public class User {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String age;
@OneToOne
@JoinColumn(name = "address_id", referencedColumnName = "id")
private Address address;
}
和
public class Address {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String building;
private String country;
@OneToOne(mappedBy = "address")
private User user;
}
在我的表格地址中,我有几行。
当我用数据插入表用户时
{
"id":null,
"name":"Foo",
"age":"18",
"address":{
"id":1,
"building":"Too",
"country":"ABS"
}
}
表用户有 1 行 address_id =1。
我插入与上面相同的数据
表用户有 2 行 address_id =1。
我的回答是:为什么一对一连接的2个表会出现上述情况?
【问题讨论】:
标签: spring-boot jpa spring-data-jpa spring-data