-->
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: Newbie: Querying one side of many-to-many relationship
PostPosted: Mon Aug 28, 2006 9:10 pm 
Newbie

Joined: Wed Oct 26, 2005 11:55 pm
Posts: 14
Hibernate version: 3.1.3

I've got a typical many-to-many realtionship between EntityA and EntityB. EntityA has a property that is a Set of EntityBs, like so:

Code:
<set name="entityBs" fetch="join">
   <key column="B_ID" not-null="true" />
   <many-to-many column="B_ID" class="EntityB"  />
</set>


I want to query to find all EntityA instances that contain a particular EntityB in their set. I've got it working with the following HQL query:

Code:
from EntityA where :bID in elements(entityBs)


and I call setLong("bID", idOfTheBInstanceImLookingFor);

Although this appears to be working, it seems to me that there would be a more "clean" way to structure such a query. I'd like to use the Criteria API if possible, but I am not a relational thinker and my perusal of the refernce docs didn't make it obvious how to do so.
The HQL I have doesn't seem all that straightforward, especially since I will eventually have to query against several different m-t-m realtionships that EntityA has Sets for (meaning my HQL would end up with a series of ORs in the where clause - yuck).

Can anyone offer a better way to structure such a query (possibly using Criteria)? Seems like it would be a common kind of requirement.

Thanks in advance,
Eric


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 11:15 pm 
Newbie

Joined: Wed Oct 26, 2005 11:55 pm
Posts: 14
I'm surprised there is no response to this - at least an RTFM :-)
Seems to me like it would be pretty straightforward for any reasonably-experienced Hibernater to answer - an easy credit point.

Did I do a poor job of phrasing the question, or violate some unwritten rule of Hibernate etiquette? ;-)

Eric


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.