title: "Delete Where" cascade delete in Hibernate?
body: <p>I am trying to cascade delete rows in a join table via one of its foreign keys and it has another table related to it that I would like to remove all rows associated with this ID as well.  So it looks like the diagram below.  When I use Session.delete(reqCandObject) with hibernate it works fine and cascades through deleting the One entry from the candidate_jobReq table as well as the associated comments.  However, I want to delete <em>all</em> of the candidate_jobReq entries that have a certain candidate ID (and also delete the comments)  I tried the function below but unlike the nice hibernate.delete(object) function, this one runs into a foreign key constraint error.  How can I delete these rows while having hibernate cascade the delete for me?</p>
  
  <p><img src="https://i.stack.imgur.com/yl1qs.png" alt="enter image description here"></p>
  
  <pre><code>public void deleteWhere(String selectionCase){
      Session hibernateSession = this.getSession();
      try {
          hibernateSession.beginTransaction();
          Query q = hibernateSession.createQuery("delete "+ type.getSimpleName() +" where " + selectionCase);
          q.executeUpdate();
          hibernateSession.getTransaction().commit();
      } finally {
          hibernateSession.close();
      }
  }
  </code></pre>