我试图弄清楚如何对@ManyToOne 关系执行批量删除,到目前为止没有成功。
设想:
父母有很多下载,我想删除父母日期为的所有下载> :some_date
。我不想删除任何父记录,只是下载记录。下载有一个使用 @ManyToOne 注释映射的父字段。
我正在尝试在 Download 实体上使用 @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
有什么建议么?