3
我有一個實體的用戶,併爲用戶我的DB值:更新現有的列值
name totalScore
--------------------
ABC 25
XYZ 30
現在我想運行查詢
update user set totalScore=totalScore+ (2*totalScore);
我們怎樣才能achive它通過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();