×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Fabio Clem
Added: May 25, 2017 1:32 PM
Views: 2362
Tags: no tags
  1.     protected EntityManager entityManager = FactoryEntityManager.getInstance();
  2.  
  3.     public void cadastrar(Object a) throws Exception {
  4.         entityManager.getTransaction().begin();
  5.         entityManager.persist(a);
  6.         entityManager.getTransaction().commit();
  7.     }
  8.  
  9.     public void editar(Object a) throws Exception {
  10.         try {
  11.             entityManager.getTransaction().begin();
  12.             entityManager.merge(a);
  13.             entityManager.getTransaction().commit();
  14.         } catch (Exception e) {
  15.             throw e;
  16.         }
  17.     }
  18.  
  19.     public void excluir(Object a) throws Exception {
  20.         try {
  21.             entityManager.getTransaction().begin();
  22.             entityManager.remove(this.entityManager.merge(a));
  23.             entityManager.getTransaction().commit();
  24.         } catch (Exception e) {
  25.             throw e;
  26.         }
  27.     }