i have an Entity User, and my DB value for user is:
name totalScore
--------------------
ABC 25
XYZ 30
Now i want to run the query
update user set totalScore=totalScore+ (2*totalScore);
How can we achive it through JPA 2.1 CriteriaUpdate ???
CriteriaBuilder criteriaBuilder = em().getCriteriaBuilder();
//Updates the salary to 90,000 of all Employee's making more than 100,000.
CriteriaUpdate update = criteriaBuilder.createCriteriaUpdate(User.class);
Root user = update.from(User.class);
Expression<Long> abc=user.get("totalScore");
update.set("totalScore", ?? );
// what expression is here to be used to replace old value with new
Query query = em().createQuery(update);
int rowCount = query.executeUpdate();
CriteriaUpdate
bypasses optimistic locking. If you wanted to use optimistic locking here, how would that be accomplished? – Timework