【发布时间】:2018-01-06 18:35:58
【问题描述】:
@OneToMany(mappedBy="columnOne", orphanRemoval=true, cascade=CascadeType.ALL)
@LazyCollection(LazyCollectionOption.FALSE)
private List<Constraint> constraints = new ArrayList<Constraint>();
每当父子记录更新时,子表记录也应该更新。
当我厌倦了 session.SaveOrUpdate() 时,父表记录得到更新,但每次插入新记录时子表都没有更新,这会导致重复数据
当厌倦了 session.merge() 时,出现错误,A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: com 因为约束可能为空,因为子表并非总是有数据
为了解决这个问题,尝试设置空集合,但这会导致数据库中有很多行具有空值。
即使子表数据可能为空,是否有任何方法可以同时更新 Parent 和 Child
【问题讨论】: