最近写了个hql语句选择表中某字段不为空的记录,结果查询不到结果。
from ApplyTable a where a.remark!= null
后来发现不为空不能这么表达,要是这样的 is not null 。然后修改hql语句,OK。
from ApplyTable a where a.remark is not null
HQL语句正确使用
本文分享了在使用HQL语句查询数据库时的一个常见错误:使用!= null来判断字段是否为空。正确的做法是使用is not null。文章通过一个具体的例子展示了如何修正这一错误。
最近写了个hql语句选择表中某字段不为空的记录,结果查询不到结果。
from ApplyTable a where a.remark!= null
后来发现不为空不能这么表达,要是这样的 is not null 。然后修改hql语句,OK。
from ApplyTable a where a.remark is not null

被折叠的 条评论
为什么被折叠?