"Delete Where" cascaded sleep hibernation?

I am trying to cascade delete rows in a connection table through one of my foreign keys, and it has another table associated with it that would also like to delete all rows associated with this identifier. So it looks like the diagram below. When I use Session.delete (reqCandObject) with hibernate, it works fine and cascades by deleting one entry from the candidate_jobReq table, as well as its related comments. However, I want to delete all the candidate_jobReq entries that have a specific candidate identifier (as well as delete comments). I tried the function below, but unlike the hibernate.delete (object) function, it runs in a foreign key constraint error. How can I delete these lines when sleep mode cascades deletion for me?

enter image description here

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();
    }
}
+4
1

Hibernate . delete , /. , .

:

  • selectionCase. , session.delete.
  • . delete. , . , .
+4

All Articles