1
UPDATE  tablename SET  col1 = :col1value WHERE id.col2=:col2 Value 
ORDER BY col3 ASC LIMIT 2;

I need an alternative for the above query, as LIMIT keyword is not accepted in HQL. setMaxResults works only for select query.

Idea is, for the query to update all the records corresponding to col1value but one.(LIMIT value can be calculated and is available)

Lucky
  • 16,787
  • 19
  • 117
  • 151

1 Answers1

0

limit cannot be used in HQL and query.setMaxResults() doesnt work with UPDATE.

Alternatively you can follow below approach:

Write two separate HQL queries where the results of the first query is fed into second query which does the update something lik below

1.first query on IDs only having limited result set (as per you limit set- setMaxResults()).

3.Second query would update based on results of first query WHERE id IN (result of first query)

shankarsh15
  • 1,947
  • 1
  • 11
  • 16