Example usage for org.hibernate SessionFactory openSession

List of usage examples for org.hibernate SessionFactory openSession

Introduction

In this page you can find the example usage for org.hibernate SessionFactory openSession.

Prototype

Session openSession() throws HibernateException;

Source Link

Document

Open a Session .

Usage

From source file:cd_modelos_dao.EmpleadosDAO.java

public void eliminarEmpleado(String cedula) {
    List<Empleados> lista = new LinkedList<>();
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session s = sf.openSession();
    Query q = s.createQuery("delete from Empleados where cedula = :cedula");
    q.setString("cedula", cedula);
    q.executeUpdate();//  w  w  w .  j  a  v a 2  s .  c  o m
    s.close();

    //        SessionFactory sf = HibernateUtil.getSessionFactory();
    //        Session s = sf.openSession();
    //        Servicios ser = consultarServicioPorId(id);
    //        System.out.println("el servicio es " + ser.getNombre());
    //        System.out.println("el servicio es " + ser.getId());
    //        s.delete(ser);
    //        s.close();
}

From source file:cd_modelos_dao.EmpleadosDAO.java

public Empleados actualizarEmpleado(int cedula, String nombre, String apellido, String telefono, String correo,
        String HV) {//ww w.  jav  a  2s  .c  o  m
    SessionFactory sf = HibernateUtil.getSessionFactory();

    try {
        Session s = sf.openSession();
        Transaction t = s.beginTransaction();
        Empleados u = new Empleados(cedula, nombre, apellido, telefono, correo, HV);
        s.update(u);
        t.commit();
        s.close();
        return u;
    } catch (HibernateException he) {
        he.printStackTrace();
    }

    return null;
}

From source file:cd_modelos_dao.EmpleadosDAO.java

public List<Empleados> obtenerEmpleados() {
    List<Empleados> lista = new LinkedList<>();
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session s = sf.openSession();
    Query q = s.createQuery("from Empleados");
    lista = q.list();/* w  w w.j  a  va2  s . co  m*/
    s.close();
    return lista;
}

From source file:cd_modelos_dao.EtapasDAO.java

public List<Etapas> obtenerEtapas() {
    List<Etapas> lista = new LinkedList<>();
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session s = sf.openSession();
    Query q = s.createQuery("from Etapas");
    lista = q.list();/*from  ww  w  . j a  va  2s  .c  om*/
    s.close();

    return lista;
}

From source file:cd_modelos_dao.EtapasPlantaDAO.java

public void ingresarEtapasPlanta(EtapasPlanta ep) {
    SessionFactory sf = null;
    Transaction t = null;//from w w w .ja  va 2 s. co m
    Session s = null;
    try {
        sf = HibernateUtil.getSessionFactory();
        s = sf.openSession();
        t = s.beginTransaction();
        s.save(ep);
    } catch (Exception e) {
    }
}

From source file:cd_modelos_dao.EtapasPlantaDAO.java

public void ingresarActualizarEtapasPlanta(EtapasPlanta ep) {
    SessionFactory sf = null;
    Transaction t = null;/* ww  w . j  a  va2  s  .  c  o  m*/
    Session s = null;
    try {
        sf = HibernateUtil.getSessionFactory();
        s = sf.openSession();
        t = s.beginTransaction();
        s.saveOrUpdate(ep);
    } catch (Exception e) {
    }
}

From source file:cd_modelos_dao.EtapasPlantaDAO.java

public void actualizarEtapasPlanta(EtapasPlanta ep) {
    SessionFactory sf = null;
    Transaction t = null;/*  w w  w.j  ava2  s  .  co  m*/
    Session s = null;
    try {
        sf = HibernateUtil.getSessionFactory();
        s = sf.openSession();
        t = s.beginTransaction();
        s.update(ep);
        t.commit();
    } catch (Exception e) {
        System.out.println("Exception " + e);
    }
}

From source file:cd_modelos_dao.EtapasPlantaDAO.java

public List<EtapasPlanta> obtenerEtapasPlanta() {
    List<EtapasPlanta> lista = new LinkedList<>();
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session s = sf.openSession();
    Query q = s.createQuery("from EtapasPlanta");
    lista = q.list();//from w  w w  . j  a v a  2 s . co m
    s.close();

    return lista;
}

From source file:cd_modelos_dao.MensajesDAO.java

public int maxId() {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session s = sf.openSession();
    Query q = s.createQuery("select max(id) from Mensajes");

    List<PlantasVenta> listado = q.list();

    try {/*from   w  ww .  j  a  va  2s  .c o  m*/
        return Integer.parseInt(listado.get(0) + "");
    } catch (Exception e) {
        return 0;
    }
}

From source file:cd_modelos_dao.MensajesDAO.java

public void ingresarMensaje(String nombre, String correo, String cad) {
    Mensajes mensaje = new Mensajes(maxId() + 1, new Date(), cad, correo, nombre);
    //System.out.println("--------------->>>"+mensaje.getId());
    SessionFactory sf = null;
    Transaction t = null;// w ww.  java 2  s.  c om
    Session s = null;

    try {
        sf = HibernateUtil.getSessionFactory();
        s = sf.openSession();
        t = s.beginTransaction();
        s.save(mensaje);
        t.commit();
        s.close();

    } catch (Exception e) {
        t.rollback();
        throw new RuntimeException("No se pudo guardar.");
    }
}