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
HQL "is null" And "!= null" on an Oracle column
提问by Eric V
Does hibernateconvert column != null
in HQLto a column is null
in SQL?
是否冬眠转换column != null
在HQL到column is null
在SQL?
回答by Eduard
That is a binary operator in hibernate you should use
那是您应该使用的休眠中的二元运算符
is not null
Have a look at 14.10. Expressions
回答by JB Nizet
No. You have to use is null
and is not null
in HQL.
不,您必须在 HQL 中使用is null
和is not null
。
回答by Boris Brodski
If you do want to use null
values with '='
or '<>'
operators you may find the
如果您确实想使用null
带有'='
或'<>'
运算符的值,您可能会发现
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 param
either 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 中处理条件空值,了解有关如何处理与空值和非空值进行比较的提示和技巧。