-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem with "order by': the alias is lost in the SQL
PostPosted: Tue Aug 07, 2007 4:08 pm 
Beginner
Beginner

Joined: Thu Jan 06, 2005 6:21 pm
Posts: 23
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: The one shipped with Seam 2.0.BETA

Full stack trace of any exception that occurs:

MySQL 5.0

I have the following HQL code :
Code:
select new SomeClass(p.id, p.name, ..., (z.latitude*z.latitude + z.longitude*z.longitude) as distance)
from Zipcode as z, FosaBakiPosting as p
where p.zipcode = z.zipcode
and p.zipcode in (...)
order by distance desc


That generate the following SQL:
Code:
select fosabakipo0_.ID as col_0_0_, fosabakipo0_.NAME as col_1_0_, ... , zipcode2_.LATITUDE*zipcode2_.LATITUDE+zipcode2_.LONGITUDE*zipcode2_.LONGITUDE as col_9_0_
from FOSA_BAKI fosabakipo0_, PC_ZIPCODE zipcode2_
where fosabakipo0_.ZIPCODE=zipcode2_.ZIPCODE
and (fosabakipo0_.ZIPCODE in ('94086' , '94087'))
order by distance desc limit ?


Hibernate doesn't complain about having 'as distance' in the class constructor of the select, but loses the alias in the generated SQL.
Therefore, the 'order by distance' is not correct and should be
'order by col_9_0_'

Is this a bug or I just tried to do something that's not supported?
If I can't do it, what would be a way to achieve this without giving up populating the class with the result?

Thanks,

Richard


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 08, 2007 8:56 am 
Beginner
Beginner

Joined: Thu Jan 06, 2005 6:21 pm
Posts: 23
Any thought on this?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.