2012-09-25 52 views
2

我有以下兩個實體:問題「刪除的對象將被重新保存通過級聯」

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; 

使用

012刪除子對象,即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): 

請幫助。

回答

1

您需要從dealCheckList中刪除清單對象。 您的DealCheckList列表有「級聯全部」,所以如果它有一個對象,它會自動保存它。

錯誤消息非常清楚「從關聯中刪除刪除的對象」

+0

同意。錯誤消息不會比那個更清晰:) +1 –

相關問題