JPA&x2B;EclipseLink-在@OneToMany关系中移动实体
我对OneToMany关系的实现如下所述: 实体组:JPA&x2B;EclipseLink-在@OneToMany关系中移动实体,jpa,one-to-many,Jpa,One To Many,我对OneToMany关系的实现如下所述: 实体组: @Entity public class Group { @OneToMany(cascade = { CascadeType.ALL }, orphanRemoval = true) private List<Unit> units = new ArrayList<Unit>(); public void addUnit(Unit unit) { this.units.add(unit); i
@Entity
public class Group {
@OneToMany(cascade = { CascadeType.ALL }, orphanRemoval = true)
private List<Unit> units = new ArrayList<Unit>();
public void addUnit(Unit unit) {
this.units.add(unit);
if (unit.getGroup() != this) {
unit.setGroup(this);
}
}
现在我想在两个组之间移动1个单元,使用:
组(第2组)
完成该操作后,我可以在数据库中的关系表GROUP_UNIT中看到
该单元现在与组1和组2相关
如何在两组之间正确移动设备?您应该在注释中添加mappedBy:
@OneToMany(cascade = { CascadeType.ALL }, orphanRemoval = true, mappedBy="Group")
private List<Unit> units = new ArrayList<Unit>();
@OneToMany(cascade={CascadeType.ALL},orphaneremovation=true,mappedBy=“Group”)
私有列表单位=新的ArrayList();
使用mappedBy,您将不再需要JOIN_表
@OneToMany(cascade = { CascadeType.ALL }, orphanRemoval = true, mappedBy="Group")
private List<Unit> units = new ArrayList<Unit>();