2

我有以下两个实体:

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;

删除子对象时,即 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):

请帮忙。

4

1 回答 1

1

您需要从 dealCheckList 中删除清单对象。您的 DealCheckList 列表具有 "cascade all" ,因此如果其中包含对象,则会自动保存它。

错误消息很清楚“从关联中删除已删除的对象”

于 2012-09-25T14:05:21.487 回答