示例#1
0
  public List<Contacto> getList() throws Exception {

    Session session = NewHibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();
    try {
      return (List<Contacto>) session.createCriteria(Contacto.class).list();
    } catch (Exception e) {
      session.getTransaction().rollback();
      session.close();
      System.err.println(e.getMessage());
      throw e;
    } finally {
      session.close();
    }
  }
示例#2
0
 public boolean update(Contacto a) throws Exception {
   Session session = NewHibernateUtil.getSessionFactory().openSession();
   session.beginTransaction();
   try {
     session.update(a);
     session.getTransaction().commit();
     session.close();
     return true;
   } catch (Exception e) {
     session.getTransaction().rollback();
     session.close();
     System.err.println(e.getMessage());
     throw e;
   }
 }
示例#3
0
 public int add(Contacto a) throws Exception {
   Session sessionA = NewHibernateUtil.getSessionFactory().openSession();
   sessionA.beginTransaction();
   int id;
   try {
     sessionA.save(a);
     id = a.getIdContacto();
     sessionA.getTransaction().commit();
     sessionA.close();
     return id;
   } catch (Exception e) {
     sessionA.getTransaction().rollback();
     sessionA.close();
     System.err.println(e.getMessage());
     throw e;
   }
 }