public void create(UserEntity userEntity) throws PreexistingEntityException, RollbackFailureException, Exception {
        if (userEntity.getProjectEntityList() == null) {
            userEntity.setProjectEntityList(new ArrayList<ProjectEntity>());
        }
        EntityManager em = null;
        try {
            utx.begin();
            em = getEntityManager();
            List<ProjectEntity> attachedProjectEntityList = new ArrayList<ProjectEntity>();
            for (ProjectEntity projectEntityListProjectEntityToAttach : userEntity.getProjectEntityList()) {
                projectEntityListProjectEntityToAttach = em.getReference(projectEntityListProjectEntityToAttach.getClass(), projectEntityListProjectEntityToAttach.getName());
                attachedProjectEntityList.add(projectEntityListProjectEntityToAttach);
            }
            userEntity.setProjectEntityList(attachedProjectEntityList);
            em.persist(userEntity);
            for (ProjectEntity projectEntityListProjectEntity : userEntity.getProjectEntityList()) {
                UserEntity oldUserNameOfProjectEntityListProjectEntity = projectEntityListProjectEntity.getUserName();
                projectEntityListProjectEntity.setUserName(userEntity);
                projectEntityListProjectEntity = em.merge(projectEntityListProjectEntity);
                if (oldUserNameOfProjectEntityListProjectEntity != null) {
                    oldUserNameOfProjectEntityListProjectEntity.getProjectEntityList().remove(projectEntityListProjectEntity);
                    oldUserNameOfProjectEntityListProjectEntity = em.merge(oldUserNameOfProjectEntityListProjectEntity);
                }
            }
            utx.commit();
        } catch (Exception ex) {
            try {
                utx.rollback();
            } catch (Exception re) {
                throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re);
            }
            if (findUserEntity(userEntity.getName()) != null) {
                throw new PreexistingEntityException("UserEntity " + userEntity + " already exists.", ex);
            }
            throw ex;
        } finally {
            if (em != null) {
                em.close();
            }
        }
    }