-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: hql - alias? to capture calculation
PostPosted: Mon Nov 07, 2005 12:44 pm 
Beginner
Beginner

Joined: Tue May 03, 2005 11:45 pm
Posts: 43
Hibernate version: 3.1

Name and version of the database you are using: mysql 5


I have this great hql below. I want to also capture the distance being calculated as well. Currently the resultset is a Business object. Is there a simple way to do a alias or something and have the distance set on my Business object as well?

String hql = "from Business biz where biz.name like :criteria and "+
" acos( " +
" sin(:lat) * sin(biz.address.latitude) + " +
" cos(:lat) * cos(biz.address.latitude) * " +
" cos(biz.address.longitude - :lon) " +
" ) * 3956 < :distance order by biz.currentRating desc";

Query query = session.createQuery(hql)
.setInteger("distance", radius)
.setString("criteria", likeCriteria)
.setDouble("lat", targetZip.getLatitude())
.setDouble("lon", targetZip.getLongitude())
.setFirstResult(offset)
.setMaxResults(RESULTS_PER_PAGE);


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 07, 2005 4:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
<formula>

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 8:50 am 
Beginner
Beginner

Joined: Tue May 03, 2005 11:45 pm
Posts: 43
ahhhh yes ... I did see this briefly in the docs, this should work perfectly, thanks. I'll post my solution when complete.


Top
 Profile  
 
 Post subject: this won't work
PostPosted: Tue Nov 15, 2005 11:36 am 
Beginner
Beginner

Joined: Tue May 03, 2005 11:45 pm
Posts: 43
Max I don't see how this helps. At first glance is sounds ok but this distance calculation is parameterized, it's based on second lat/lon pair. Neither formulas nor filters help me here. Any suggestions?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 1:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
native sql query

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 1:48 pm 
Beginner
Beginner

Joined: Tue May 03, 2005 11:45 pm
Posts: 43
Yes but I was hoping for something more elegant than this. Apparently this is my only choice.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 2:36 pm 
Beginner
Beginner

Joined: Tue May 03, 2005 11:45 pm
Posts: 43
Max can you show in a simple SQL query how I might get that calculated value into my business object?

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 10:56 pm 
Beginner
Beginner

Joined: Tue May 03, 2005 11:45 pm
Posts: 43
See the solution here:

http://forum.hibernate.org/viewtopic.ph ... 14#2271614


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.