public BusinessGroup findGroupAttendedBy(Identity identity, String groupName, BGContext bgContext) {
String query = "select bgi from " + " org.olat.group.BusinessGroupImpl as bgi "
+ ", org.olat.basesecurity.SecurityGroupMembershipImpl as sgmi" + " where bgi.name = :name "
+ " and bgi.partipiciantGroup = sgmi.securityGroup" + " and sgmi.identity = :identId" + " and bgi.groupContext = :context";
DB db = DBFactory.getInstance();
DBQuery dbq = db.createQuery(query);
dbq.setEntity("identId", identity);
dbq.setString("name", groupName);
dbq.setEntity("context", bgContext);
List res = dbq.list();
if (res.size() == 0) return null;
else if (res.size() > 1) throw new AssertException("more than one result row found for (identity, groupname, context) ("
+ identity.getName() + ", " + groupName + ", " + bgContext.getName());
return (BusinessGroup) res.get(0);
}