-->
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.  [ 1 post ] 
Author Message
 Post subject: HQL query to do two subselects
PostPosted: Thu Aug 09, 2007 8:30 am 
Newbie

Joined: Tue Aug 07, 2007 10:36 am
Posts: 3
I've this structure:
1) class Widget has a lot of MemberTypes (many-to-many)
2) class MemberType has a lot of Members (many-to-many)

I want to get all Page objects that are associated with Member via MemberTypes. I'm trying to do that this way:
Code:
SELECT
   w from Widget w, Member m, MemberType mt
WHERE
   mt in elements(m.MemberTypes)
   AND w in elements(mt.Widgets)
   AND (w.WidgetType & 1) <> 0
   AND m.ID = 15
ORDER BY w.Name


This can return couple widgets with the same key as Member can be associated with couple MemberTypes and different MemberTypes can be associated with the same Widget. So we can have situation:

MemberA have types TypeB and TypeC. TypeB is associated with WidgetD and WidgetE. TypeC is associated with WidgetD and WidgetF. This query then returns WidgetD, WidgetE, WidgetD and WidgetF. Of course I want WidgetD only once in list.

For now I just used DISTINCT like that:
Code:
SELECT DISTINCT
   w from Widget w, Member m, MemberType mt (...)


Problem
But it is not the best option as slows down database queries. Is there any approach to this problem so I can start from Member object and list all Widgets that are somehow associated with Widget (in other words "there is a path from Member to Widget")?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.