It's not a secret anymore!*
The moose likes Object Relational Mapping and the fly likes Complex math in HQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply locked New topic
Author

Complex math in HQL

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

I have a table named LOCATIONS mapped to an entity named Location.

The SQL that works for me is as follows:

select ZipCode,sqrt( square(:latitudeValue - Latitude) + square(:longitudeValue - Longitude)) as distance from LOCATIONS order by distance

which, when I limit the returned list to single value, gives me the record I need.

What's the HQL equivalent? I'm just used to referencing entity properties...


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

just as an aside, it may be easier on the database (but check first) if you omit the sqrt in the SQL/HQL and apply it to the code afterwards.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

DB is SQL Server (if it makes nay difference).
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Sorry, I posted a possible HQL in your other thread.

You can always also just stick with the SQL.

I like the HQL version though. Check your other thread.

Thanks

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

Thanks Mark. I'll close this one to prevent duplication.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Complex math in HQL
 
Similar Threads
Generic problem
completely lost
How to get "closest to" values in a query?
Hibernate Annotations -- NamedQueries
Find geographical records based on zip code and radius