String q = " select count(grp) from" + " org.olat.group.BusinessGroupImpl as grp," + " org.olat.group.area.BGAreaImpl as area,"
+ " org.olat.group.area.BGtoAreaRelationImpl bgarel," + " org.olat.basesecurity.SecurityGroupMembershipImpl as secgmemb"
+ " where area.name = :name" + " and bgarel.groupArea = area" + " and bgarel.businessGroup = grp"
+ " and grp.groupContext = :context" + " and ((grp.partipiciantGroup = secgmemb.securityGroup and secgmemb.identity = :id) "
+ " or (grp.ownerGroup = secgmemb.securityGroup and secgmemb.identity = :id)) ";
DBQuery query = DBFactory.getInstance().createQuery(q);
query.setEntity("id", identity);
query.setEntity("context", groupContext);
query.setString("name", areaName);
query.setCacheable(true);
List result = query.list();
if (result.size() == 0) return false;
return ( ((Long) result.get(0)).intValue() > 0);
}