gpt4 book ai didi

hibernate - JPA:如何使用HQL检查NULL查询参数值?

转载 作者:行者123 更新时间:2023-12-03 14:07:16 25 4
gpt4 key购买 nike

Query query =  em.createQuery(
"select count(u) from User u where (u.id=:a) and (u.photo=:b)")
.setParameter("a",userId).setParameter("b",null);

就我而言,我想检查用户照片是否上传(照片值是否为空)。
我试过上面的查询。

最佳答案

参见example in Hibernate documentation
您应该检查参数是否为空:

Query query =  em.createQuery(
"select count(u) from User u where (u.id=:userId) and (u.photo is null)")
.setParameter("userId",userId);

关于hibernate - JPA:如何使用HQL检查NULL查询参数值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15216547/

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