sql - JPA Query for toggling a boolean in a UPDATE -
sql version works okay , can toggle boolean called bar ...
mysql> update foo set bar = ! bar id in (1, 7, 13); query ok, 3 rows affected (0.02 sec) is there easy jpa query equivalent, tried
final set<integer> ids; final query query = em.createquery("update " + foo.class.getname() + " set bar= !bar" + " a.id in :ids"); query.setparameter("ids", ids); query.executeupdate(); the above gives org.hibernate.queryexception.
in entity :
@column(columndefinition = "integer", nullable = false) private boolean bar; any ideas on jpa syntax ?
that can done case expression:
update foo set a.bar = case a.bar when true false else true end a.id in :ids for nullable boolean bit more needed:
update foo set a.bar = case a.bar when true false when false true else a.bar end a.id in :ids sql jpa jpql
No comments:
Post a Comment