【发布时间】:2021-03-03 21:01:02
【问题描述】:
我想从新克隆的父实体中删除子实体。这样新实体就没有原始父级的所有子级,而只有其他属性
父实体
public class AlertDetail {
/** Some properties **/
@OneToMany(mappedBy = "alertDetail", cascade = CascadeType.ALL, orphanRemoval = true)
private final Set<AlertReceiverDetail> receiverDetails = new HashSet<>();
@ElementCollection(fetch = FetchType.EAGER)
private Set<AlertDataEventMetadata> dataEventMetadata = new HashSet<>();
}
当我在进行所需更改后尝试分离并保存实体时
通过分离原始实体后清除集合
entityManager.detach(alertDetail);
alertdetail.getReceiverDetails().clear();
dao.save(alertDetail);
我收到交易不存在错误
failed to lazily initialize a collection of role:
这是可以理解的,
但问题是我不希望它被急切地加载,因为该列表很大
【问题讨论】: