How to add a complex order - using Hibernate Criteria?

I use Hibernate criteria and would like to add an order-by clause that functionally matches this SQL:

order by abs(dateSubmitted - 125234234) 

Where dateSubmitted long and the number subtracted from it will be provided by the user (as a date). I am trying to order entries by their "distance" from a date provided by the user.

I tried

 criteria.addOrder("abs(dateSubmitted - " + getDateInput() + ")"); 

but that will not work.

Is it possible? Or will I have to abandon the criteria for HQL? I have successfully done this in HQL, but would like to adhere to the criteria, if possible to ensure consistency.

+7
sql-order-by hibernate criteria
source share
1 answer
+10
source share

All Articles