Oracle 列上的 HQL“为空”和“!=空”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5066492/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 03:06:05  来源:igfitidea点击:

HQL "is null" And "!= null" on an Oracle column

oraclehibernatenull

提问by Eric V

Does hibernateconvert column != nullin HQLto a column is nullin SQL?

是否冬眠转换column != nullHQLcolumn is nullSQL

回答by Eduard

That is a binary operator in hibernate you should use

那是您应该使用的休眠中的二元运算符

is not null

Have a look at 14.10. Expressions

看看14.10。表达式

回答by JB Nizet

No. You have to use is nulland is not nullin HQL.

不,您必须在 HQL 中使用is nullis not null

回答by Boris Brodski

If you do want to use nullvalues with '='or '<>'operators you may find the

如果您确实想使用null带有'=''<>'运算符的值,您可能会发现

answer from @egallardo hier

来自@egallardo hier 的回答

very useful.

很有用。

Short example for '=': The expression

简短示例'=':表达式

WHERE t.field = :param

you refactor like this

你这样重构

WHERE ((:param is null and t.field is null) or t.field = :param)

Now you can set the parameter parameither to some non-null value or to null:

现在您可以将参数设置param为某个非空值或null

query.setParameter("param", "Hello World"); // Works
query.setParameter("param", null);          // Works also

回答by egallardo

No. See also this link Handle conditional null in HQLfor tips and tricks on how to handle comparisons with both null and non-null values.

否。另请参阅此链接在 HQL 中处理条件空值,了解有关如何处理与空值和非空值进行比较的提示和技巧。