I am trying to figure out how to execute a bulk delete on a @ManyToOne relationship without success.
Scenario:
Parent has many Downloads
I want to execute a delete of all Downloads where the Parent date is > :some_date.
I do not want to delete any of the Parent records, just the Download records.
Download has a parent field that is mapped using a @ManyToOne annotation.
I am trying to use a @NamedQuery on the Download entity do accomplish this.
//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
Any suggestions? Thanks!