-->
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.  [ 3 posts ] 
Author Message
 Post subject: critera for retrieving many-to-many association
PostPosted: Mon Sep 28, 2009 10:57 am 
Newbie

Joined: Tue Nov 11, 2008 8:33 am
Posts: 5
Hi all
I have a mapping such as A has a m-t-m B. I wish to retrieve all B which belongs to A, which is a very simple task using HQL, but as the filtering restrictions could vary, I'd like to use a criteria.

HQL would look like:
select b from A a
left join a.b b
where a.id = 1

But what would the criteria be like?

Please help me out

//Swanthe


Top
 Profile  
 
 Post subject: Re: critera for retrieving many-to-many association
PostPosted: Tue Sep 29, 2009 5:12 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 6:39 am
Posts: 44
Location: Mumbai, India
Please refer

http://docs.jboss.org/hibernate/stable/ ... yhql-joins

_________________
Thx,
Murugesan.
Web: http://www.murugesanpitchandi.com


Top
 Profile  
 
 Post subject: Re: critera for retrieving many-to-many association
PostPosted: Tue Sep 29, 2009 4:51 pm 
Newbie

Joined: Tue Nov 11, 2008 8:33 am
Posts: 5
Thanks for your pointer Murugesan, but the HQL is not the problem here, I got that part all right up and running. The thing is that I want to replace the query with an criteria and I guess it would look something like this:

session.createCriteria(A.class, "a")
.createCriteria("a.listOfB", "b", Criteria.LEFT_JOIN)
.add(Restrictions.eq("a.id", 1))

My problem is that this will give me a list of "a" with the same size as the number of "b" belonging to "a" with a.id=1, but what I'm looking for is a list of "b".

//Swanthe


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