protected TypedQuery<UserGroupMembershipEntity> getUserGroupMappingQuery(GroupModel group) { TypedQuery<UserGroupMembershipEntity> query = em.createNamedQuery("userMemberOf", UserGroupMembershipEntity.class); query.setParameter("user", getEntity()); query.setParameter("groupId", group.getId()); return query; }
@Override public void joinGroup(GroupModel group) { if (isMemberOf(group)) return; UserGroupMembershipEntity entity = new UserGroupMembershipEntity(); entity.setUser(getEntity()); entity.setGroupId(group.getId()); em.persist(entity); em.flush(); em.detach(entity); }