java - How can I add a value to a column? -
i want add value existing column, don't want have select first. right have like
// run hql in named query employee id = :id // after running above e.setbonus(e.getbonus() + 100); // add 100 e's bonus // commit database hibernateutil.saveorupdate(e);
but want that's one-and-done - like
update employee e set e.bonus = e.bonus + 100
is can in hibernate? if so, how. if not, what's suggested best practice such update?
you create hql query update
query updatebonus = createquery("update employee set bonus = bonus+100 id = :id" ); updatebonus.setinteger("id", employee.getid()); updatebonus.executeupdate();
Comments
Post a Comment