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:app.Ejer2.java

public static SeguroAnotaciones readSeguro(int clavePrimaria) {
    SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
    Session session = sessionFactory.openSession();

    SeguroAnotaciones seguro = (SeguroAnotaciones) session.get(SeguroAnotaciones.class, clavePrimaria);

    System.out.println(seguro.getNombre());

    session.close();//from  w w  w . ja v a  2  s .co m

    return seguro;

}

From source file:app.Ejer2.java

public static void updateSeguro(SeguroAnotaciones seguro) {
    SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
    Session session = sessionFactory.openSession();

    seguro.setNombre("Edgar Modificado");

    session.beginTransaction();/*from ww  w  . j a  v  a 2s.c  o m*/
    session.update(seguro);
    session.getTransaction().commit();

    session.close();
}

From source file:app.Ejer2.java

public static void deleteSeguro(SeguroAnotaciones seguro) {
    SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
    Session session = sessionFactory.openSession();

    session.beginTransaction();/*  w  w w  .  j a  v a  2 s.  c  om*/
    session.delete(seguro);
    session.getTransaction().commit();

    session.close();

}

From source file:appcostal.model.DAO.java

public List<Hermano> hermanosDisponibles() {
    List<Hermano> hermanos;
    SessionFactory s = HibernateUtil.getSessionFactory();
    Session se;//from   w ww. j a v  a2  s  .  c om
    se = s.openSession();
    Transaction tx = se.beginTransaction();
    Query q = se.createQuery("From Hermano");
    hermanos = (List<Hermano>) q.list();
    tx.commit();
    se.close();
    return hermanos;
}

From source file:appcostal.model.DAO.java

public Hermano buscaHermano(String email, String clave) {
    Hermano hermano = null;/* w  w  w  .  ja  v  a  2  s.c  om*/
    SessionFactory s = HibernateUtil.getSessionFactory();
    Session se;
    se = s.openSession();
    Transaction tx = se.beginTransaction();
    Query q = se.createQuery("From Hermano where email='" + email + "' and clave='" + clave + "'");
    List<Hermano> lista = (List<Hermano>) q.list();
    if (!lista.isEmpty()) {
        hermano = lista.get(0);
    }
    tx.commit();
    se.close();
    return hermano;
}

From source file:appcostal.model.DAO.java

public void Insertar(Object obj) {
    SessionFactory s = HibernateUtil.getSessionFactory();
    Session se;//from   w w  w .  j  ava2  s. co m
    se = s.openSession();
    Transaction tx = se.beginTransaction();
    try {
        se.save(obj);
    } catch (Exception e) {
        System.out.println("error");
    }
    tx.commit();
    se.close();
}

From source file:appcostal.model.DAO.java

public Hermano obtenerHermano(String dni) {
    Hermano hermano = null;/*from www  . j  a v a2  s. co  m*/
    SessionFactory s = HibernateUtil.getSessionFactory();
    Session se;
    se = s.openSession();
    Transaction tx = se.beginTransaction();
    Query q = se.createQuery("From Hermano where dni='" + dni + "'");
    List<Hermano> lista = (List<Hermano>) q.list();
    if (!lista.isEmpty()) {
        hermano = lista.get(0);
    }
    tx.commit();
    se.close();
    return hermano;
}

From source file:appcostal.model.DAO.java

public void actualizar(Object obj) {
    SessionFactory s = HibernateUtil.getSessionFactory();
    Session se;// w  ww . j  a  v a2  s. c  o m
    se = s.openSession();
    Transaction tx = se.beginTransaction();
    se.update(obj);
    tx.commit();
    se.close();
}

From source file:appcostal.model.DAO.java

public void eliminar(Object obj) {
    SessionFactory s = HibernateUtil.getSessionFactory();
    Session se;/* w ww  .  j a  v a2  s  .co m*/
    se = s.openSession();
    Transaction tx = se.beginTransaction();
    se.delete(obj);
    tx.commit();
    se.close();
}

From source file:appcostal.model.DAO.java

public List<Paso> pasosDisponibles() {
    List<Paso> pasos;//from   w w w.  java  2 s. c o  m
    SessionFactory s = HibernateUtil.getSessionFactory();
    Session se;
    se = s.openSession();
    Transaction tx = se.beginTransaction();
    Query q = se.createQuery("From Paso");
    pasos = (List<Paso>) q.list();
    tx.commit();
    se.close();
    return pasos;
}