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

OracleHibernateNull

Oracle Problem Overview


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

Oracle Solutions


Solution 1 - Oracle

That is a binary operator in hibernate you should use

is not null

Have a look at 14.10. Expressions

Solution 2 - Oracle

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

Solution 3 - Oracle

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

Solution 4 - Oracle

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEric VView Question on Stackoverflow
Solution 1 - OracleEduardView Answer on Stackoverflow
Solution 2 - OracleJB NizetView Answer on Stackoverflow
Solution 3 - OracleBoris BrodskiView Answer on Stackoverflow
Solution 4 - OracleegallardoView Answer on Stackoverflow