Boolean needToAdd =
((Long) getEntityManager().createQuery(queryText).setParameter("groupId", groupId).setParameter(
"personId", personId).getSingleResult()).equals(0L);
if (needToAdd)
{
getEntityManager().persist(new RequestedGroupMembership(groupId, personId));
getEntityManager().flush();
}
return needToAdd;
}