Bookmark Topic Watch Topic
  • New Topic

Complex math in HQL

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
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...
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
DB is SQL Server (if it makes nay difference).
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Thanks Mark. I'll close this one to prevent duplication.
 
    Bookmark Topic Watch Topic
  • New Topic