HQL "is null" And "!= null" on an Oracle column
Asked Answered
C

4

67

Does hibernate convert column != null in HQL to a column is null in SQL?

Charpentier answered 21/2, 2011 at 13:24 Comment(0)
L
107

That is a binary operator in hibernate you should use

is not null

Have a look at 14.10. Expressions

Lowrie answered 21/2, 2011 at 13:29 Comment(0)
M
44

No. You have to use is null and is not null in HQL.

Multinuclear answered 21/2, 2011 at 13:26 Comment(0)
P
18

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

answer from @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 param either to some non-null value or to null:

query.setParameter("param", "Hello World"); // Works
query.setParameter("param", null);          // Works also
Paperweight answered 15/4, 2016 at 5:59 Comment(1)
Right answer, but a bit overkill :) I do it if I have no other solutions: If there is only one or two nullable param, i find it better to make many HQL or JPQL queries.Leander
C
1

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

Cartagena answered 6/2, 2014 at 3:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.