Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From <a href="http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#batch-direct" rel="nofollow">Hibernate 4.1.9 manual - section about bulk update and deletes</a>:</p> <blockquote> <p>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.</p> </blockquote> <p>Unsupported (implicit join):</p> <pre><code>DELETE A a WHERE a.relation.property = "dummy"; </code></pre> <p>A way to go:</p> <pre><code>DELETE A a WHERE a.relation.id IN (SELECT r.id FROM Relation r WHERE r.property = "dummy"); </code></pre> <p>For your example it is bit complicated but following query should work (tested in HSQL db):</p> <pre><code>UPDATE A a SET a.column3 = (SELECT b.column3 FROM B b WHERE a.column1 = b.column1 and a.column2 = b.column2) WHERE a.id IN (SELECT a.id FROM A a, B b WHERE a.column1 = b.column1 AND a.column2 = b.column2) </code></pre> <p>This query works in HSQL db, but fails in MySQL. It looks like that only possible solution is to use two separate queries: </p> <pre><code>List&lt;String&gt; list = em.createQuery("SELECT a.column1 FROM A a, B b WHERE a.column1 = b.column1 AND a.column2 = b.column2").getResultList(); em.createQuery("UPDATE A a SET a.column3 = (SELECT b.column3 FROM B b WHERE a.column1 = b.column1 and a.column2 = b.column2) WHERE a.column1 IN :list").setParameter("list", list).executeUpdate(); </code></pre> <p>The last solution is tested in mysql and works well but in your case you have to customize first select query based on your use case - my example expects that a.column1 is unique (using column1 instead of id to avoid primary key).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload