Hi, hoping somebody can point me in the right direction with a problem I'm having.
I need to retrieve a list of locations based on their vicinity to a given Place. So for example, I have "Place" and "Attraction" as mapped entities, both of which have a lat/lng.
So in SQL I could do something like:
Code:
select a.*, SQRT(POWER((69.1 * (a.latitude - PLACE_LAT)) , 2 ) + POWER((53 * (a.longitude - PLACE_LNG)), 2)) as distance from Attraction a where SQRT(POWER((69.1 * (a.latitude - PLACE_LAT)) , 2 ) + POWER((53 * (a.longitude - PLACE_LNG)), 2)) < 20;
which would get me all the Attractions with 20m of the Place, assuming I provide PLACE_LAT and PLACE_LNG to the query from my Place object.
I couldn't find a nice way to do this with Criteria, so I have now moved onto HQL and got a query which I believe works.
Code:
select a, sqrt((69.1 * (a.latitude - :lat) * 69.1 * (a.latitude - :lat)) + (53 * (a.longitude - :lng) * 53 * (a.longitude - :lng))) as distance from Attraction a where sqrt((69.1 * (a.latitude - :lat) * 69.1 * (a.latitude - :lat)) + (53 * (a.longitude - :lng) * 53 * (a.longitude - :lng))) < 20
However, my extra column "distance" now means that the objects returned from query.list() aren't of type "Attraction", they're just "Object".
I have tried declaring distance in Attraction but this creates a column in the database which I do not want, and still doesn't work. I tried declaring distance as Transient but this still doesn't work.
Any ideas? Do I need a whole new object for this result set?