jtrollin wrote:
I know this has to be documented somewhere but I can not find it.
I have a many to many (users to groups) and want to find all the users by what group they are in.
...
...
Note my groupbean does not have a set of users because I am worried about circular fetches (I get a user, that uses has a group that group has users those users have groups) if I need the group to have a set of users and have the many-to-many reflected on both sides then how do I avoid the circular fetching?
thanks
This is really pretty simple using the Criteria interface:
(Assume groupId contains the id of the group you are searching for.)
Code:
List users = session.createCriteria(UserBean.class)
.createAlias("groups","group")
.add(Restrictions.eq("group.id" ,groupId)
.list();
BTW: You don't need to worry about circular fetching. Hibernate takes care of this for you.