IFNULL equivalent in Hibernate Query Language?

Michał Bendowski picture Michał Bendowski · Nov 1, 2009 · Viewed 17.7k times · Source

I'm trying to write an HQL query which will calculate an average rating for an item. I want the query to return 0 instead of null when there are no rating for a given item - so that I can use my query as a subquery. So is it possible? Is there an HQL equivalent of IFNULL or NVL?

Answer

KLE picture KLE · Nov 1, 2009

COALESCE is the official equivalent.

It returns the first non-null of its arguments.

Example:

    COALESCE(id_pati, 0)

Link Wikipedia