-->
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: NO CLUE: Aggregate, Association....
PostPosted: Thu Apr 26, 2007 2:33 pm 
Beginner
Beginner

Joined: Thu Nov 23, 2006 5:09 am
Posts: 21
I have a similar probliem like this:

Ship stores containers, container holds boxes, boxes have a weight.

I now want to load those ships that have a total weight less than 100 tons.

In SQL it would be something like:

SELECT ship_id
FROM ship, container, box
WHERE ship.ship_id = (+)conatiner.ship_id
AND container.container_id = (+)box.container_id
GROUP BY ship.ship_id
HAVING SUM(box.weight) < 100

I tried several approaches but either I end up with the correct ships selected but only their id's, ie a List containing Integers (Root Object for Criteria was box.class). Or the call crashes cause it tries to select the weight directly from the ship object (Root Object for Criteria was ship.class)


I can't get it running, neither with HQL nor the Criteria API.


Plase, any Help welcome....


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 3:14 am 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
Just making a guess, but I think this might be the answer

select ship
from Ship ship
join ship.containers cont
join cont.boxes box
group by ship.id
having sum(box.weight) < 100


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.