public void create(Usuario usuario) throws PreexistingEntityException, Exception {
   EntityManager em = null;
   try {
     em = getEntityManager();
     em.getTransaction().begin();
     Investigador investigadorIdentificacion = usuario.getInvestigadorIdentificacion();
     if (investigadorIdentificacion != null) {
       investigadorIdentificacion =
           em.getReference(
               investigadorIdentificacion.getClass(),
               investigadorIdentificacion.getIdentificacion());
       usuario.setInvestigadorIdentificacion(investigadorIdentificacion);
     }
     em.persist(usuario);
     if (investigadorIdentificacion != null) {
       investigadorIdentificacion.getUsuarioList().add(usuario);
       investigadorIdentificacion = em.merge(investigadorIdentificacion);
     }
     em.getTransaction().commit();
   } catch (Exception ex) {
     if (findUsuario(usuario.getNombre()) != null) {
       throw new PreexistingEntityException("Usuario " + usuario + " already exists.", ex);
     }
     throw ex;
   } finally {
     if (em != null) {
       em.close();
     }
   }
 }
 public void destroy(String id) throws NonexistentEntityException {
   EntityManager em = null;
   try {
     em = getEntityManager();
     em.getTransaction().begin();
     Usuario usuario;
     try {
       usuario = em.getReference(Usuario.class, id);
       usuario.getNombre();
     } catch (EntityNotFoundException enfe) {
       throw new NonexistentEntityException(
           "The usuario with id " + id + " no longer exists.", enfe);
     }
     Investigador investigadorIdentificacion = usuario.getInvestigadorIdentificacion();
     if (investigadorIdentificacion != null) {
       investigadorIdentificacion.getUsuarioList().remove(usuario);
       investigadorIdentificacion = em.merge(investigadorIdentificacion);
     }
     em.remove(usuario);
     em.getTransaction().commit();
   } finally {
     if (em != null) {
       em.close();
     }
   }
 }
 public void edit(Usuario usuario) throws NonexistentEntityException, Exception {
   EntityManager em = null;
   try {
     em = getEntityManager();
     em.getTransaction().begin();
     Usuario persistentUsuario = em.find(Usuario.class, usuario.getNombre());
     Investigador investigadorIdentificacionOld =
         persistentUsuario.getInvestigadorIdentificacion();
     Investigador investigadorIdentificacionNew = usuario.getInvestigadorIdentificacion();
     if (investigadorIdentificacionNew != null) {
       investigadorIdentificacionNew =
           em.getReference(
               investigadorIdentificacionNew.getClass(),
               investigadorIdentificacionNew.getIdentificacion());
       usuario.setInvestigadorIdentificacion(investigadorIdentificacionNew);
     }
     usuario = em.merge(usuario);
     if (investigadorIdentificacionOld != null
         && !investigadorIdentificacionOld.equals(investigadorIdentificacionNew)) {
       investigadorIdentificacionOld.getUsuarioList().remove(usuario);
       investigadorIdentificacionOld = em.merge(investigadorIdentificacionOld);
     }
     if (investigadorIdentificacionNew != null
         && !investigadorIdentificacionNew.equals(investigadorIdentificacionOld)) {
       investigadorIdentificacionNew.getUsuarioList().add(usuario);
       investigadorIdentificacionNew = em.merge(investigadorIdentificacionNew);
     }
     em.getTransaction().commit();
   } catch (Exception ex) {
     String msg = ex.getLocalizedMessage();
     if (msg == null || msg.length() == 0) {
       String id = usuario.getNombre();
       if (findUsuario(id) == null) {
         throw new NonexistentEntityException("The usuario with id " + id + " no longer exists.");
       }
     }
     throw ex;
   } finally {
     if (em != null) {
       em.close();
     }
   }
 }