我有以下两个实体:
1- 交易
@OneToMany(cascade=CascadeType.ALL,mappedBy = "deal", fetch = FetchType.EAGER)
@Fetch( FetchMode.SELECT)
private List<DealCheckList> dealCheckList;
2- 交易清单
@JoinColumn(name = "DEAL_ID", referencedColumnName = "DEAL_ID", insertable = false, updatable = false)
@ManyToOne(fetch = FetchType.LAZY)
private Deal deal;
删除子对象时,即交易清单使用
.......
.......
transaction = session.beginTransaction();
Deal deal = (Deal) session.createCriteria(Deal.class)
.add(Restrictions.eq("dealId", dealId)).uniqueResult();
for(DealCheckList checklist : deal.getDealCheckList()){
session.delete(checklist);
}
transaction.commit();
我收到以下错误
Caused by: org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations):
请帮忙。
您需要从交易清单中删除清单对象。您的交易清单列表具有"级联所有",因此如果其中包含一个对象,则会自动保存它。
错误消息非常清楚"从关联中删除已删除的对象"