【发布时间】:2013-10-15 05:54:28
【问题描述】:
我想获取联系电话不为空的Patient(POJO 类)的记录。所以,我提到了这个post。
在答案中指定了两种方式
SELECT *
FROM table
WHERE YourColumn IS NOT NULL;
SELECT *
FROM table
WHERE NOT (YourColumn <=> NULL);
从上面我写到下面的 hql 运行成功
from Patient p where p.contactNo is not null
但是,对于第二种类型的 hql
from Patient p where not (p.contactNo <=> null)
抛出异常
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: >
如何在 HQL 中使用 mysql null safe equality operator <=>?
【问题讨论】:
-
为什么要使用 from Patient p where not (p.contactNo null) 当您可以使用 from Patient p where p 轻松实现所需结果时.contactNo 不为空
-
@AnkitSharma:我只是在检查两种方式。我想知道为什么会导致异常?或者我们不能在 HQL 中使用。