Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

SQL to HQL translation problem

Thread view: 
Jakub Kuźma - 23 Sep 2007 09:51 GMT
Hello,

I am newbie in Java and Hibernate. I need to translate the following
SQL query:

select t.*, v.capacity - sum(d.weight) as capacity
from transits t
join deliveries d on t.id = d.transitid
join vehicles v on t.vehicleid = v.id
group by t.id
having capacity >= :capacityMin

... to Hibernate Query Language. I've tried with:

select t, v.capacity - sum(d.weight) as capacity
from Transit t
join t.deliveries d
join t.vehicle v
group by t.id
having capacity >= :capacityMin

But it doesn't work (no such column 'capacity'). Is there any other way
to do that?

Greetings and TIA.

Signature

Jakub Kuźma
http://jah.pl/
JID oraz e-mail w domenie gmail.com, login - qoobaa

Lew - 23 Sep 2007 17:16 GMT
> Hello,
>
[quoted text clipped - 7 lines]
> group by t.id
> having capacity >= :capacityMin

This is problematic SQL, because you are SELECTing t.* but GROUPing on t.id.
You have to use aggregate methods on all the columns that are not t.id.

Signature

Lew

Lars Enderin - 23 Sep 2007 18:19 GMT
Lew skrev:

Just checking what happens with charset.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.