Saturday, February 23, 2013

Hibernate delete and update queries with joins

From Hibernate 4.1.9 manual - section about bulk update and deletes:

No implicit or explicit joins can be specified in a bulk HQL query. Sub-queries can be used in the where-clause, where the subqueries themselves may contain joins.

Unsupported (implicit join)

DELETE A a WHERE a.relation.property = "dummy";

A way to go

DELETE A a WHERE a.relation.id IN (SELECT r.id FROM Relation r WHERE r.property = "dummy");

3 comments:

  1. I presume your example 1 is supposed to be a join with some other table here?

    ReplyDelete
  2. I presume your example 1 is supposed to be a join with some other table here?

    ReplyDelete
  3. Thanks! I found that post after googling for about one hour and it solved my problem with an update HQL query.

    ReplyDelete