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