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:cl.model.dao.UsuarioDAO.java

public void ingresarUsuario(Usuario usuario) {
    SessionFactory sf = null;
    Session session = null;// www . ja va 2s  . co m
    Transaction tx = null;
    try {
        sf = HibernateUtil.getSessionFactory();
        session = sf.openSession();
        tx = session.beginTransaction();
        session.save(usuario);
        tx.commit();
        session.close();
    } catch (Exception ex) {
        tx.rollback();
        throw new RuntimeException("No se pudo registrar el usuario");
    }
}

From source file:cl.model.dao.UsuarioDAO.java

public void modificarUsuario(Usuario usuario) {
    SessionFactory sf = null;
    Session session = null;/*from  ww  w.j  a v  a2 s .co  m*/
    Transaction tx = null;
    try {
        sf = HibernateUtil.getSessionFactory();
        session = sf.openSession();
        tx = session.beginTransaction();
        session.save(usuario);
        tx.commit();
        session.close();
    } catch (Exception ex) {
        tx.rollback();
        throw new RuntimeException("No se pudo modificar el usuario");
    }
}

From source file:cl.model.dao.UsuarioDAO.java

public int consultarUsuario(int codigo) {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session session = sf.openSession();
    Usuario usuario = (Usuario) session.get(Usuario.class, codigo);
    if (usuario != null) {
        return 1;
    } else {/*  w ww  .  jav a 2 s  .  c  om*/
        return 0;
    }
}

From source file:cl.model.dao.UsuarioDAO.java

public List<Usuario> findAll() {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session session = sf.openSession();
    Query query = session.createQuery("from Usuario");
    List<Usuario> lista = query.list();
    session.close();/*from   w  w w  .  j av  a2  s  . c o m*/
    return lista;
}

From source file:cl.model.dao.UsuarioDAO.java

public void eliminar(int codigo) {
    SessionFactory sf = null;
    Session session = null;/*ww w.  j  a  v a2  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 usuario");
    }
}

From source file:cl.model.dao.WorkshopDAO.java

public void ingresarWorkshop(Workshop workshop) {
    SessionFactory sf = null;
    Session session = null;/*from  ww w .  j av  a 2  s .  c o  m*/
    Transaction tx = null;
    try {
        sf = HibernateUtil.getSessionFactory();
        session = sf.openSession();
        tx = session.beginTransaction();
        session.save(workshop);
        tx.commit();
        session.close();
    } catch (Exception ex) {
        tx.rollback();
        throw new RuntimeException("No se pudo registrar el workshop");
    }
}

From source file:cl.model.dao.WorkshopDAO.java

public void modificarWorkshop(Workshop workshop) {
    SessionFactory sf = null;
    Session session = null;//from   www  . j  av  a 2s  .  c  o m
    Transaction tx = null;
    try {
        sf = HibernateUtil.getSessionFactory();
        session = sf.openSession();
        tx = session.beginTransaction();
        session.save(workshop);
        tx.commit();
        session.close();
    } catch (Exception ex) {
        tx.rollback();
        throw new RuntimeException("No se pudo modificar el workshop");
    }
}

From source file:cl.model.dao.WorkshopDAO.java

public int consultarWorkshop(int codigo) {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session session = sf.openSession();
    Workshop workshop = (Workshop) session.get(Workshop.class, codigo);
    if (workshop != null) {
        return 1;
    } else {/*from  w ww  .  j  av a2 s.c  om*/
        return 0;
    }
}

From source file:cl.model.dao.WorkshopDAO.java

public List<Workshop> findAll() {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session session = sf.openSession();
    Query query = session.createQuery("from Workshop");
    List<Workshop> lista = query.list();
    session.close();//from ww w .  jav a 2 s.  com
    return lista;
}

From source file:cl.model.dao.WorkshopDAO.java

public void eliminar(int codigo) {
    SessionFactory sf = null;
    Session session = null;/*from   w ww .j a  v  a2 s.  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 el workshop");
    }
}