Hibernate, HSQL, and Update w/ Limits

前端 未结 1 1102
暖寄归人
暖寄归人 2021-01-21 16:50

Is it possible to limit the number of rows that are updated using Hibernate/HQL? For instance:

Query q = em.createQuery(\"UPDATE MyObj o Set o.prop = :prop\");
         


        
相关标签:
1条回答
  • 2021-01-21 17:33

    Try HSQLDB 2.0 (the latest snapshot jars, not the GA) with Hibernate 3.5.5

    It does require an inner select with LIMIT at the end but this no longer requires an ORDER BY. Also, ORDER BY can use an index if it is the same index as the one used for SELECT.

    An example would be like:

    UPDATE MyObj o SET o.prop = :prop WHERE o.id IN (SELECT id FROM MyObj LIMIT 10)
    
    0 讨论(0)
提交回复
热议问题