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.
Maybe create your own Order class, like this:
http://blog.tremend.ro/2008/06/10/how-to-order-by-a-custom-sql-formulaexpression-when-using-hibernate-criteria-api/
I'm going to use this :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With