Hi all,
I've read various old threads about how to do this in Hibernate, but I'm just making sure.
I have a Group objects, which contains a member Set of User objects, named memberUsers. I want to build a Criteria-based query that returns all Group objects whose memberUsers Set contains a given User.
By what I've been reading, my query function should be something like this:
List<Group> getGroupsWithUser(User user)
{
Criteria crit = session.createCriteria(Group.class);
Criteria userCrit = crit.createCriteria("memberUsers");
userCrit.add(Restrictions.eq("this", user));
return crit.list();
}
Can someone confirm, or modify, what is needed to get this to work? Other threads seem to base the criteria on being given some property of a User object in memberUsers, *not* what to do if given a User entity itself. It was buried somewhere that "this" should be used as the Restriction.
Thanks for any confirmation!
--Scott
|