简体   繁体   中英

HQL NOT operator issue

I want to translate the following mysql query to HQL

UPDATE `table` SET `my_bool` = NOT my_bool

And also I need to change only the row with the selected id

My attempt below

UPDATE Model m SET m.flag = NOT m.flag WHERE m.id is :id 

function(Integer id){
     StringBuilder queryBuilder = new StringBuilder("UPDATE Model m SET m.flag = NOT m.flag WHERE m.id is :id");
     this.em.createQuery(queryBuilder.toString());
}

I get the following error:

unexpected token: NOT

I have just started learning HQL and the documentation says it is a valid operator

11.6.9. NOT predicate operator

The NOT operator is used to negate the predicate that follows it. If that following predicate is true, the NOT resolves to false. If the predicate is true, NOT resolves to false. If the predicate is unknown, the NOT resolves to unknown as well.

Can you please help

It works for me:

UPDATE Model m SET m.flag = !m.flag WHERE m.id = :id 

And C# code:

var query =  container.Resolve<ISession>().CreateQuery(hql);
query.SetParameter("id", 1);
query.ExecuteUpdate();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM