我想弄清楚如何對@ManyToOne關係執行批量刪除,到目前爲止沒有成功。如何使用EJB3中的關係執行批量刪除
場景:
家長有很多朋友下載,我想執行一個刪除所有下載,其中母公司日期是> :some_date
的。我不想刪除任何父記錄,只是下載記錄。下載具有使用@ManyToOne批註映射的父字段。
我想在下載實體上使用@NamedQuery來完成此操作。
//this OQL tries to delete from both the child and parent tables
//I only want to delete from the Download table
DELETE FROM Download dwn
WHERE dwn.acctId = :acctId AND dwn.parent.date > :date
//this OQL is invalid and will keep the bean from deploying
//The example I found used this sub query but with a @OneToMany relationship
//instead of a @ManyToOne relationship
//this is what i get for an error on deployment:
//"Errors in named queries: deleteByAccountIdAndDownloadedDate"
DELETE FROM Download dwn WHERE EXISTS
(SELECT p from dwn.parent WHERE p.date > :date)
AND dwn.acctId = :acctId
有什麼建議嗎?
我將檢查來自我的DBA的級聯設置。 – 2009-07-10 10:43:24