Hi,
I want to select Users that belong to Public groups or don't belong to any groups at all. user<->group is a many to many assiociation. I have to use detachedCriterias, so I do as follows:
DetachedCriteria crit = DetachedCriteria.forClass(User.class, "usr");
crit.createAlias("groups", "usrgroups");
Disjunction dis1 = Restrictions.disjunction();
dis1.add(Property.forName("usr.groups").isEmpty());
dis1.add(Property.forName("usrgroups.isPublic").eq(new Boolean(true)));
crit.add(dis1);
...
but this doesn't work, since creating alias on collection 'groups' eliminates users which have no groups (calling isEmpty() gives zero results). How to overcome that?
regards,
Chris
|