我有以下两个实体:
1-交易
@OneToMany(cascade=CascadeType.ALL,mappedBy = "deal", fetch = FetchType.EAGER)
@Fetch( FetchMode.SELECT)
private List<DealCheckList> dealCheckList;
2-DealCheckList
@JoinColumn(name = "DEAL_ID", referencedColumnName = "DEAL_ID", insertable = false, updatable = false)
@ManyToOne(fetch = FetchType.LAZY)
private Deal deal;
在删除子对象即DealCheckList时使用
.......
.......
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):
请帮忙。
最佳答案
您需要从DealCheckList中删除清单对象。
您的DealCheckList列表具有“ cascade all”,因此,如果其中包含对象,则将自动保存它。
错误消息很清楚“从关联中删除已删除的对象”