List of usage examples for org.hibernate SessionFactory openSession
Session openSession() throws HibernateException;
From source file:cl.model.dao.DetallePrestamoDAO.java
public void ingresar(DetallePrestamo detalle) { SessionFactory sf = null; Session session = null;/* w w w . ja v a2s. c o m*/ Transaction tx = null; try { sf = HibernateUtil.getSessionFactory(); session = sf.openSession(); tx = session.beginTransaction(); session.save(detalle); tx.commit(); session.close(); } catch (Exception ex) { tx.rollback(); throw new RuntimeException("No se pudo registrar el detalle del prestamo"); } }
From source file:cl.model.dao.DetallePrestamoDAO.java
public void modificar(DetallePrestamo detalle) { 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(detalle); tx.commit(); session.close(); } catch (Exception ex) { tx.rollback(); throw new RuntimeException("No se pudo modificar el detalle del prestamo"); } }
From source file:cl.model.dao.DetallePrestamoDAO.java
public int consultar(int codigo) { SessionFactory sf = HibernateUtil.getSessionFactory(); Session session = sf.openSession(); DetallePrestamo detalle = (DetallePrestamo) session.get(DetallePrestamo.class, codigo); if (detalle != null) { return 1; } else {/* w w w . j av a 2s .co m*/ return 0; } }
From source file:cl.model.dao.DetallePrestamoDAO.java
public List<DetallePrestamo> findAll() { SessionFactory sf = HibernateUtil.getSessionFactory(); Session session = sf.openSession(); Query query = session.createQuery("from DetallePrestamo"); List<DetallePrestamo> lista = query.list(); session.close();/* w w w.jav a 2s.c om*/ return lista; }
From source file:cl.model.dao.DetallePrestamoDAO.java
public void eliminar(int codigo) { SessionFactory sf = null; Session session = null;/*from ww w . j a v a 2 s. c o m*/ 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 el detalle"); } }
From source file:cl.model.dao.EmpleadoDAO.java
public void ingresarEmpleado(Employee emp) { SessionFactory sf = null; Session session = null;/*from w ww .ja va 2 s .c om*/ Transaction txn = null; try { sf = HibernateUtil.getSessionFactory(); session = sf.openSession(); txn = session.beginTransaction(); session.save(emp); txn.commit(); session.close(); } catch (Exception e) { txn.rollback(); throw new RuntimeException("No se pudo guardar detalles de empleado"); } }
From source file:cl.model.dao.EmpleadoDAO.java
public String consultarEmpleado(int codigo) { SessionFactory sf = HibernateUtil.getSessionFactory(); Session session = sf.openSession(); Employee emp = (Employee) session.get(Employee.class, codigo); session.close();//from ww w. ja v a 2s. c om if (emp != null) { return "El empleado con codigo " + emp.getId() + "cuyo nombre es " + emp.getName() + "ocupa la posicion de " + emp.getRole() + " y fue ingresado el sistema la fecha" + emp.getInsertTime(); } else { return "El codigo de empleado " + codigo + "no pudo ser encontrado"; } }
From source file:cl.model.dao.EmpleadoDAO.java
public List<Employee> verEmpleados() { SessionFactory sf = HibernateUtil.getSessionFactory(); Session session = sf.openSession(); Query query = session.createQuery("from Employee"); List<Employee> lista = query.list(); session.close();//from w ww. jav a2 s . c o m return lista; }
From source file:cl.model.dao.InscripcionesDAO.java
public void ingresarInscrito(InscripcionesWorkshop inscrito) { SessionFactory sf = null; Session session = null;// ww w.j ava 2 s .co m Transaction tx = null; try { sf = HibernateUtil.getSessionFactory(); session = sf.openSession(); tx = session.beginTransaction(); session.save(inscrito); tx.commit(); session.close(); } catch (Exception ex) { tx.rollback(); throw new RuntimeException("No se pudo registrar la inscripcion"); } }
From source file:cl.model.dao.InscripcionesDAO.java
public void modficarInscrito(InscripcionesWorkshop inscrito) { SessionFactory sf = null; Session session = null;/* w w w . jav a 2s . co m*/ Transaction tx = null; try { sf = HibernateUtil.getSessionFactory(); session = sf.openSession(); tx = session.beginTransaction(); session.save(inscrito); tx.commit(); session.close(); } catch (Exception ex) { tx.rollback(); throw new RuntimeException("No se pudo modificar la inscripcion"); } }