public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException {
        EntityManager em = null;
        try {
            em = getEntityManager();
            em.getTransaction().begin();
            PypAdmAgend pypAdmAgend;
            try {
                pypAdmAgend = em.getReference(PypAdmAgend.class, id);
                pypAdmAgend.getId();
            } catch (EntityNotFoundException enfe) {
                throw new NonexistentEntityException("The pypAdmAgend with id " + id + " no longer exists.", enfe);
            }
            List<String> illegalOrphanMessages = null;
            List<PypAdmAsistCon> pypAdmAsistConListOrphanCheck = pypAdmAgend.getPypAdmAsistConList();
            for (PypAdmAsistCon pypAdmAsistConListOrphanCheckPypAdmAsistCon : pypAdmAsistConListOrphanCheck) {
                if (illegalOrphanMessages == null) {
                    illegalOrphanMessages = new ArrayList<String>();
                }
                illegalOrphanMessages.add("This PypAdmAgend (" + pypAdmAgend + ") cannot be destroyed since the PypAdmAsistCon " + pypAdmAsistConListOrphanCheckPypAdmAsistCon + " in its pypAdmAsistConList field has a non-nullable idAgend field.");
            }
            if (illegalOrphanMessages != null) {
                throw new IllegalOrphanException(illegalOrphanMessages);
            }
            PypAdmProgramas idPrograma = pypAdmAgend.getIdPrograma();
            if (idPrograma != null) {
                idPrograma.getPypAdmAgendList().remove(pypAdmAgend);
                idPrograma = em.merge(idPrograma);
            }
            InfoPaciente idPaciente = pypAdmAgend.getIdPaciente();
            if (idPaciente != null) {
                idPaciente.getPypAdmAgendList().remove(pypAdmAgend);
                idPaciente = em.merge(idPaciente);
            }
            em.remove(pypAdmAgend);
            em.getTransaction().commit();
        } finally {
            if (em != null) {
                em.close();
            }
        }
    }