I've been having difficulty coming up with an HQL query the does something which seems like it should be very simple.
I need to select a value based on whether or not it is null. For example, let's say I have a table with
userrating and
overrideRating columns, where
overrideRating may (and in most cases is)
null.
I want
overrideRating to override
userrating, and sort by that value. I was able to do this in SQL as follows:
Code:
SELECT IF (overriderating is not null, overriderating, userrating) as rating
FROM myobjects
ORDER BY rating desc
How would I express this in HQL? I
don't need to have my hibernate properties mapped to this computed value. I just want to sort by this computed value.