public void destroy(Integer id) throws NonexistentEntityException, RollbackFailureException, Exception { EntityManager em = null; try { utx.begin(); em = getEntityManager(); Usuario usuario; try { usuario = em.getReference(Usuario.class, id); usuario.getIdusuario(); } catch (EntityNotFoundException enfe) { throw new NonexistentEntityException( "The usuario with id " + id + " no longer exists.", enfe); } em.remove(usuario); utx.commit(); } catch (Exception ex) { try { utx.rollback(); } catch (Exception re) { throw new RollbackFailureException( "An error occurred attempting to roll back the transaction.", re); } throw ex; } finally { if (em != null) { em.close(); } } }
public void edit(Usuario usuario) throws NonexistentEntityException, RollbackFailureException, Exception { EntityManager em = null; try { utx.begin(); em = getEntityManager(); usuario = em.merge(usuario); utx.commit(); } catch (Exception ex) { try { utx.rollback(); } catch (Exception re) { throw new RollbackFailureException( "An error occurred attempting to roll back the transaction.", re); } String msg = ex.getLocalizedMessage(); if (msg == null || msg.length() == 0) { Integer id = usuario.getIdusuario(); if (findUsuario(id) == null) { throw new NonexistentEntityException("The usuario with id " + id + " no longer exists."); } } throw ex; } finally { if (em != null) { em.close(); } } }