user = query.getSingleResult();
} catch (NoResultException exception) {
throw new UnknownUserException("user with email '" + email + "' is not a registered user");
}
ShareList shareList;
try {
shareList = entityManager.createNamedQuery("mySharedLists", ShareList.class)
.setParameter("loginName", currentUser.getIdentifier()).getSingleResult();
} catch (NoResultException e) {
shareList = new ShareList();
shareList.setUser(entityManager.find(TodoListUser.class, currentUser.getIdentifier()));
}
shareList.getSharedWith().add(user);
entityManager.persist(shareList);
entityManager.flush();
}