public void edit(Command command) throws NonexistentEntityException, Exception {
EntityManager em = null;
try {
em = getEntityManager();
em.getTransaction().begin();
Command persistentCommand = em.find(Command.class, command.getName());
Collection<Usergroup> usergroupCollectionOld = persistentCommand.getUsergroupCollection();
Collection<Usergroup> usergroupCollectionNew = command.getUsergroupCollection();
Collection<Usergroup> attachedUsergroupCollectionNew = new ArrayList<Usergroup>();
for (Usergroup usergroupCollectionNewUsergroupToAttach : usergroupCollectionNew) {
usergroupCollectionNewUsergroupToAttach = em.getReference(usergroupCollectionNewUsergroupToAttach.getClass(), usergroupCollectionNewUsergroupToAttach.getId());
attachedUsergroupCollectionNew.add(usergroupCollectionNewUsergroupToAttach);