-->
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: HQL join question regarding subclasses
PostPosted: Sat Oct 01, 2005 7:12 pm 
Beginner
Beginner

Joined: Thu May 05, 2005 4:49 pm
Posts: 30
I have the classes City, Resort, Activity and Deal. Activity has two subclasses - CityActivity and ResortActivity - which each have a reference back to their respective City / Resort.

The classes are related like:

City many-many CityActivity
Resort 1-many ResortActivity
Activity many-many Deal

I want to create an HQL query that returns all the deals for a given resort, by joining "through" the activities table. I have:

select distinct d from Deal d join d.activities a join a.resort r where r.id = ?

but I can't use the "resort" attribute of the activity a in the above query, since all activities don't have a resort property. Only the ResortActivity has a resort property.

Do I have to split up my activities collection into two collections - one ResortActivities collection and one CityActivities collection - and then join to a.resortActivities?

This seems akward. I would be able to do the query in standard JDBC if I did something like:

select distinct d from deals d, deal_activities da, activities a where d.id = da.deal_id and da.activity_id = a.id and a.resort_id = ?

Thanks!


Top
 Profile  
 
 Post subject: Re: HQL join question regarding subclasses
PostPosted: Sun Oct 02, 2005 2:31 pm 
Beginner
Beginner

Joined: Sun Jul 31, 2005 1:23 pm
Posts: 35
How about:

Code:
FROM ResortActivity AS ra JOIN ra.resort AS r JOIN ra.deals AS d WHERE r.id = ?


That should do what you want and return a list of tuples with the third element containing the Deals that you want.

If this doesn't work, which inheritance model are you using?

Please rate if this was helpful; I need the points to post.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 5:39 am 
Beginner
Beginner

Joined: Mon Sep 22, 2003 5:18 am
Posts: 28
You can try to add class specification so that only certain type of polymorph entity should be considered while joing activties to deals


Top
 Profile  
 
 Post subject: thank you
PostPosted: Mon Oct 03, 2005 3:39 pm 
Beginner
Beginner

Joined: Thu May 05, 2005 4:49 pm
Posts: 30
That worked flawlessly - I think I was braindead when I made that post. How do I assign credits? I don't see a link for that option.


Top
 Profile  
 
 Post subject: argh
PostPosted: Mon Oct 03, 2005 3:41 pm 
Beginner
Beginner

Joined: Thu May 05, 2005 4:49 pm
Posts: 30
Found it - 1 credit to each of you.


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.