Dear Hibernate Experts,
I need to order the results of a query by a calculated value. Specifically, I have a table with columns Latitude and Longitude and I need to order by Euclidean distance from 0, 0. In other words, i need "ORDER BY Latitude * Latitude + Longitude * Longitude" (Because sqrt is a strictly increasing function it can be omitted w/o changing the results).
I am using a DetachedCriteria rather than HQL to obtain my results. But I don't mind switching to HQL if there is a way to do it using HQL. Perhaps I can use createAlias in some way and then order by the alias?
Please help! I've been searching everywhere for the answer to this question!
Thanks very much,
Adam
|