Two Laptop Bag
The moose likes Object Relational Mapping and the fly likes Complex math in HQL Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


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: 56549
    
  14

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...


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About 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: 56549
    
  14

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

Joined: Feb 05, 2001
Posts: 17243
    
    1

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: 56549
    
  14

Thanks Mark. I'll close this one to prevent duplication.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Complex math in HQL
 
Similar Threads
How to get "closest to" values in a query?
completely lost
Find geographical records based on zip code and radius
Generic problem
Hibernate Annotations -- NamedQueries