i need to convert this HQL:
FROM Appointment a WHERE (a.group==null OR :user MEMBER OF a.group.groupMembers)
to criteria. How can i archieve that a subcriteria is only used when a maincriteria is not matching?
i tried something like that, but i’m stuck:
Criteria subcrit = crit.createCriteria("group");
subcrit.createAlias("groupMembers", "gmembers");
crit.add(Restrictions.or(Restrictions.eq("group", null), Restrictions.eq("gmembers.snuserId", user.getId())));
Ok i found a soulution for me:
first i created a detached criteria, which finds all group ids where the user is member:
Then for my main criteria:
Hope it helps someone