gpt4 book ai didi

mysql - HQL NOT 运算符问题

转载 作者:行者123 更新时间:2023-11-29 11:46:05 24 4
gpt4 key购买 nike

我想将以下 mysql 查询转换为 HQL

UPDATE `table` SET `my_bool` = NOT my_bool

而且我只需要更改具有所选 id 的行

我的尝试如下

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());
}

我收到以下错误:

unexpected token: NOT

我刚刚开始学习 HQL 和 documentation说它是一个有效的运算符

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.

请帮忙

最佳答案

它对我有用:

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

和 C# 代码:

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

关于mysql - HQL NOT 运算符问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34921001/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com