-->
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.  [ 5 posts ] 
Author Message
 Post subject: Need some helps on HQL
PostPosted: Mon Oct 29, 2007 12:22 pm 
Regular
Regular

Joined: Wed Aug 25, 2004 7:40 pm
Posts: 65
I have the following classes:
Code:
Category
CategorizedOrganization
Organization
Address

The relationships between them are the followings:

Category & CategorizedOrganization: one-to-many
CategorizedOrganization & Organization: one-to-one (the first one contains the second one)
Organziation & address: one-to-many

I need to find out all organizations under a given category and in a given city (one attribute of the address) .

The following HQL doesn't yield a right result.
Code:
select o from Category c left join c.categorizedOrganizations co left join fetch co.organzation o left join c.addresses a where c.id = ? and a.city = ?

Can someone help me out on this HQL, please.

Hibernate version:
3.x


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 29, 2007 11:17 pm 
Newbie

Joined: Wed Feb 07, 2007 7:55 pm
Posts: 18
Since the first half of the HQL is a condition in fact, a subquery seems to be a good fit. How about the folloing HQL?
Code:
select o from organzation o left join c.addresses a where o in (select  o2 from Category c left join c.categorizedOrganizations co left join co.organization o2 where c.id = ?) and a.city = ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 30, 2007 3:45 am 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
Shouldn't the statement be


select o from Category c left join c.categorizedOrganizations co left join co.organzation o left join o.addresses a where c.id = ? and a.city = ?

_________________
Please rate this post if you find it helpful


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 30, 2007 1:19 pm 
Regular
Regular

Joined: Wed Aug 25, 2004 7:40 pm
Posts: 65
sethrohit1977 wrote:
Shouldn't the statement be


select o from Category c left join c.categorizedOrganizations co left join co.organzation o left join o.addresses a where c.id = ? and a.city = ?

The desired object won't be created without "fetch"?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 30, 2007 1:26 pm 
Regular
Regular

Joined: Wed Aug 25, 2004 7:40 pm
Posts: 65
hm0 wrote:
Since the first half of the HQL is a condition in fact, a subquery seems to be a good fit. How about the following HQL?
Code:
select o from organzation o left join c.addresses a where o in (select  o2 from Category c left join c.categorizedOrganizations co left join co.organization o2 where c.id = ?) and a.city = ?

The subquery approach seems to make the thought clear.


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