try {
GroupDefinition found = (GroupDefinition) query.getSingleResult();
if ((id == null) // null == id means creating new def - so if query has results, it's a dup
|| (found.getId() != id)) // found != id means updating def - so if query has result, only dup if ids don't match
{
throw new GroupDefinitionAlreadyExistsException("GroupDefinition with name " + name + " already exists");
}
} catch (NoResultException e) {
// user is changing the name of the group, this is OK
return true;
}