List of usage examples for org.hibernate SessionFactory openSession
Session openSession() throws HibernateException;
From source file:cl.model.dao.ComponenteDAO.java
public String crearComponete(Componente c) { SessionFactory sf; Session session = null;/*from ww w . j a va 2 s .c om*/ Transaction tx = null; String response = ""; try { sf = HibernateUtil.getSessionFactory(); session = sf.openSession(); tx = session.beginTransaction(); session.save(c); tx.commit(); response = "Componente creado exitosamente"; } catch (Exception ex) { tx.rollback(); throw new RuntimeException("No se pudo crear el componente"); } session.close(); return response; }
From source file:cl.model.dao.ComponenteDAO.java
public Componente leerComponente(int id) { SessionFactory sf = HibernateUtil.getSessionFactory(); Session session = sf.openSession(); Componente c = (Componente) session.get(Componente.class, id); //session.close(); if (c != null) { return c; } else {//from w w w . j av a 2 s. com return null; } }
From source file:cl.model.dao.ComponenteDAO.java
public List<Componente> listaComponente() { SessionFactory sf = HibernateUtil.getSessionFactory(); Session session = sf.openSession(); Query q = session.createQuery("from Componente"); List<Componente> lista = q.list(); //session.close(); return lista; }
From source file:cl.model.dao.ComponenteDAO.java
public String actualizarComponete(Componente c) { SessionFactory sf; Session session;/*from w w w . ja v a 2 s. c o m*/ Transaction tx = null; String response; try { sf = HibernateUtil.getSessionFactory(); session = sf.openSession(); Componente compo = (Componente) session.get(Componente.class, c.getId()); compo.setDescripcion(c.getDescripcion()); compo.setNombre(c.getNombre()); compo.setEstado(c.isEstado()); tx = session.beginTransaction(); session.update(compo); tx.commit(); response = "Componente actualizado exitosamente"; } catch (Exception ex) { tx.rollback(); response = "No se pudo actualizar el componente"; } return response; }
From source file:cl.model.dao.ComponenteDAO.java
public String cambiarStatusComponete(int id) { SessionFactory sf; Session session;/*from ww w .j a v a 2s . c o m*/ Transaction tx = null; String response; try { sf = HibernateUtil.getSessionFactory(); session = sf.openSession(); Componente compo = (Componente) session.get(Componente.class, id); compo.setEstado(!compo.isEstado()); tx = session.beginTransaction(); session.update(compo); tx.commit(); response = "El estado de " + compo.getNombre() + " fue actualizado exitosamente"; } catch (Exception ex) { tx.rollback(); response = "No se pudo actualizar el componente"; } return response; }
From source file:cl.model.dao.CuentaDAO.java
public void ingresar(Cuenta cuenta) { SessionFactory sf = null; Session session = null;/*from ww w . ja v a 2 s . c om*/ Transaction tx = null; try { sf = HibernateUtil.getSessionFactory(); session = sf.openSession(); tx = session.beginTransaction(); session.save(cuenta); tx.commit(); session.close(); } catch (Exception ex) { tx.rollback(); throw new RuntimeException("No se pudo registrar la cuenta"); } }
From source file:cl.model.dao.CuentaDAO.java
public void modificar(Cuenta cuenta) { SessionFactory sf = null; Session session = null;//from www . j av a2 s. com Transaction tx = null; try { sf = HibernateUtil.getSessionFactory(); session = sf.openSession(); tx = session.beginTransaction(); session.save(cuenta); tx.commit(); session.close(); } catch (Exception ex) { tx.rollback(); throw new RuntimeException("No se pudo modificar la cuenta"); } }
From source file:cl.model.dao.CuentaDAO.java
public int consultar(int codigo) { SessionFactory sf = HibernateUtil.getSessionFactory(); Session session = sf.openSession(); Cuenta cuenta = (Cuenta) session.get(Cuenta.class, codigo); if (cuenta != null) { return 1; } else {/*from w w w . j av a 2 s . c o m*/ return 0; } }
From source file:cl.model.dao.CuentaDAO.java
public List<Cuenta> findAll() { SessionFactory sf = HibernateUtil.getSessionFactory(); Session session = sf.openSession(); Query query = session.createQuery("from Cuenta"); List<Cuenta> lista = query.list(); session.close();//w w w . j ava 2 s. c om return lista; }
From source file:cl.model.dao.CuentaDAO.java
public void eliminar(int codigo) { SessionFactory sf = null; Session session = null;// w ww .j a va 2s.c om Transaction tx = null; try { sf = HibernateUtil.getSessionFactory(); session = sf.openSession(); tx = session.beginTransaction(); session.delete(codigo); tx.commit(); session.close(); } catch (Exception ex) { tx.rollback(); throw new RuntimeException("No se pudo eliminar la cuenta"); } }