如果在关系上使用 PERSIST 级联类型,在所有者侧或另一侧保存实体有什么区别?
@Entity
public class Slot {
@OneToOne(mappedBy = "slot", cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
private Cartridge cartridge;
}
@Entity
public class Cartridge {
@OneToOne(cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
private Slot slot;
}
问题:
slot.setCartridge(cartridge);
slot.save();
对比
cartridge.setSlot(slot)
cartridge.save();
slot.save() 或弹药筒.save() 似乎不一样...
两个实体都已保存。我只是想设置它们之间的关系。