-->
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: Selecting entites based on the contents of a collection
PostPosted: Fri Nov 16, 2007 5:31 am 
Newbie

Joined: Tue Jan 09, 2007 5:24 am
Posts: 15
Hi - I need to select a list of "User" entities based on them having one or more of a specific set of "Role" entities.

The "User" entity has a list (bag-semantics) of "Role" entities called "Roles". This list is created using a many-to-many table in between.

Now, I want to create a query that retrieves all the "User" entities that has a specific "Role" in its "Roles" list. How do I do that ? I am fairly comfortable using the "ICriteria" API, but that doesn't seem to suffice here.

Any suggestions would be greatly appreciated.

Cheers,
Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 16, 2007 8:32 am 
Newbie

Joined: Wed Jul 11, 2007 9:35 am
Posts: 4
Code:
ICriteria criteria= session.CreateCriteria(typeof(User))
                          .CreateAlias("Roles", "roles")
                           Add(Expression.Eq("roles.Id", roleIdToSearchFor)



Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 16, 2007 9:22 am 
Newbie

Joined: Tue Jan 09, 2007 5:24 am
Posts: 15
Hi Oscilate - you're the man. It worked.

Thank you very much.

Thomas


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.