Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Negate unary operator in Hibernate QL

I'm trying to switch boolean field using the following hql:

update Entity e set e.booleanField = not e.booleanField where e.id = ?1;

Unfortunately "QuerySyntaxException: unexpected token: not near..." was thrown.

My question is: is there some unary operator for hibernate that supports such expression? Or any well known trick?

sql supports such queries (postgresql):

update entity_table set booleanField = not(booleanField);
like image 498
Andrey Rodionov Avatar asked Apr 25 '12 14:04

Andrey Rodionov


1 Answers

To toggle the boolean property, equivalent to the not unary operator, under HQL/JPQL, use:

UPDATE entity e SET e.booleanField = (e.booleanField=false)
like image 147
acdcjunior Avatar answered Oct 14 '22 00:10

acdcjunior