If portability is not a problem, you can ask for your own database query.
Oracle: em.createNativeQuery("update TableName SET myVar = 1 where id IN (SELECT id FROM TableName WHERE ROWNUM <= 5)").executeUpdate();
MySql: em.createNativeQuery("update TableName SET myVar = 1 where id IN (SELECT id FROM TableName LIMIT 5)").executeUpdate();
ROWNUM and LIMIT are used to limit the number of results in a query for Oracle and MySql, respectively.
Didn't mention which database you are using. If the sample code can help you, make the appropriate changes.
source
share