title: How to execute bulk delete with relationship in EJB3
body: <p>I am trying to figure out how to execute a bulk delete on a @ManyToOne relationship, so far without success.</p>
  
  <p>Scenario:</p>
  
  <p>Parent has many Downloads, I want to execute a delete of all Downloads where the Parent date is <code>&gt; :some_date</code>.  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.</p>
  
  <p>I am trying to use a @NamedQuery on the Download entity to accomplish this.</p>
  
  <pre><code>//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 &gt; :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 &gt; :date) 
      AND dwn.acctId = :acctId
  </code></pre>
  
  <p>Any suggestions?</p>