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.BoletinDAO.java

public void ingresar(Boletin boletin) {
    SessionFactory sf = null;
    Session session = null;//from w  ww. j a v  a 2s . c om
    Transaction tx = null;
    try {
        sf = HibernateUtil.getSessionFactory();
        session = sf.openSession();
        tx = session.beginTransaction();
        session.save(boletin);
        tx.commit();
        session.close();
    } catch (Exception ex) {
        tx.rollback();
        throw new RuntimeException("No se pudo registrar el boletin");
    }
}

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

public void modificar(Boletin boletin) {
    SessionFactory sf = null;
    Session session = null;/*from   ww w .  ja  v a  2s  .  c om*/
    Transaction tx = null;
    try {
        sf = HibernateUtil.getSessionFactory();
        session = sf.openSession();
        tx = session.beginTransaction();
        session.save(boletin);
        tx.commit();
        session.close();
    } catch (Exception ex) {
        tx.rollback();
        throw new RuntimeException("No se pudo modificar el boletin");
    }
}

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

public Boletin consultar(int codigo) {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session session = sf.openSession();
    Boletin boletin = (Boletin) session.get(Boletin.class, codigo);
    if (boletin != null) {
        return boletin;
    } else {/*  w ww. j a  v  a2s .co  m*/
        return new Boletin();
    }
}

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

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

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

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

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

public void ingresar(Carrera carrera) {
    SessionFactory sf = null;
    Session session = null;//w  w  w.j  a  va2s .  c  o m
    Transaction tx = null;
    try {
        sf = HibernateUtil.getSessionFactory();
        session = sf.openSession();
        tx = session.beginTransaction();
        session.save(carrera);
        tx.commit();
        session.close();
    } catch (Exception ex) {
        tx.rollback();
        throw new RuntimeException("No se pudo registrar la carrera");
    }
}

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

public void modificar(Carrera carrera) {
    SessionFactory sf = null;
    Session session = null;/*w  w  w  . j  ava2  s . c o  m*/
    Transaction tx = null;
    try {
        sf = HibernateUtil.getSessionFactory();
        session = sf.openSession();
        tx = session.beginTransaction();
        session.save(carrera);
        tx.commit();
        session.close();
    } catch (Exception ex) {
        tx.rollback();
        throw new RuntimeException("No se pudo modificar la carrera");
    }
}

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

public int consultar(int codigo) {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session session = sf.openSession();
    Carrera carrera = (Carrera) session.get(Carrera.class, codigo);
    if (carrera != null) {
        return 1;
    } else {/*from  ww  w  . ja  va2s. co m*/
        return 0;
    }
}

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

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

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

public void eliminar(int codigo) {
    SessionFactory sf = null;
    Session session = null;//from  w w  w  .jav a 2  s.co 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 la carrera");
    }
}