【发布时间】:2017-04-12 06:25:32
【问题描述】:
我目前有一个父实体知道其子实体的关系,如下所示:
@Entity
public class Parent{
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn
private Set<Child> children = new HashSet<>();
}
@Entity
public class Child{
// no link to parent
}
现在我想让它成为这样的双向关系:
@Entity
public class Parent{
@OneToMany(fetch = FetchType.LAZY, mappedBy = "parent")
private Set<Child> children = new HashSet<>();
}
@Entity
public class Child{
@ManyToOne(fetch = FetchType.LAZY)
private Parent parent;
}
底层数据库是 OracleDB。
进行上述更改时,我的现有数据会发生什么变化?如果可能的话,我们不想弄乱现有的数据。
【问题讨论】:
标签: java jpa persistence