title: Java: Hibernate - Query to delete from multiple tables
body: <p>I have two tables connected by a foreign key with a one to many relation.</p>
  
  <p>In entity A I have the following:</p>
  
  <pre><code>@org.hibernate.annotations.Cascade( {
      org.hibernate.annotations.CascadeType.ALL,
      org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
  @OneToMany(mappedBy="monitoredFlight", fetch = FetchType.LAZY)
  @OnDelete(action=OnDeleteAction.CASCADE)
  private List&lt;bTable&gt; BTable = new ArrayList&lt;BTable&gt;();
  </code></pre>
  
  <p>Now I try to delete from table A with a bulk delete query:</p>
  
  <pre><code>Query query = em.createQuery("delete from A where originDateTime&lt;:date");
  </code></pre>
  
  <p>and I get the foreign key constraint error. I decided to do the delete with a join just as I would in mysql, so I changed it to:</p>
  
  <pre><code>Query query = em.createQuery("delete from A join BTable where originDateTime&lt;:date");
  </code></pre>
  
  <p>and I got a syntax error. I have tried several combination with or without join and nothing works; any ideas?</p>
  
  <p>I am using mysql for the database and java for the language.</p>