我想弄清楚如何对@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