public Group fetchGroupForUpdate(final User user, final Long groupId)
     throws GroupNotFoundException, AccessDeniedException {
   final GroupImpl group = entityManager.find(GroupImpl.class, groupId);
   if (group == null) throw new GroupNotFoundException();
   if (group.getOwner().equals(user)) return group;
   throw new AccessDeniedException();
 }
 public void updateGroup(
     final User user, final Long groupId, final String name, final String description)
     throws GroupNotFoundException, AccessDeniedException, NameClashException {
   final GroupImpl group = entityManager.find(GroupImpl.class, groupId);
   if (group == null) throw new GroupNotFoundException();
   if (group.getOwner().equals(user)) {
     final Query query =
         entityManager.createNativeQuery(
             "update GROUPS SET NAME=:name, DESCRIPTION=:description where ID=:groupId and OWNER_ID=:userId");
     query.setParameter("name", name);
     query.setParameter("description", description);
     query.setParameter("groupId", groupId);
     query.setParameter("userId", user.getId());
     try {
       query.executeUpdate();
     } catch (EntityExistsException e) {
       throw new NameClashException();
     }
   } else throw new AccessDeniedException();
 }