I'm using Hibernate criteria and would like to add an order-by clause that is functionally the same as this SQL:
order by abs(dateSubmitted - 125234234)
Where dateSubmitted
is a long and the number subtracted from it will be user-supplied (as a date). I'm trying to order records by their 'distance' from a user supplied date.
I've tried
criteria.addOrder("abs(dateSubmitted - " + getDateInput() + ")");
but it doesn't work.
Is this possible? Or will I have to abandon criteria for HQL? I have successfully done this in HQL but would like to stick with criteria if at all possible for consistency's sake.