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:appcostal.model.DAO.java

public List<Iguala> igualasDisponibles() {
    List<Iguala> igualas;/*w ww .j a v  a2  s .  c  o m*/
    SessionFactory s = HibernateUtil.getSessionFactory();
    Session se;
    se = s.openSession();
    Transaction tx = se.beginTransaction();
    Query q = se.createQuery("From Iguala");
    igualas = (List<Iguala>) q.list();
    tx.commit();
    se.close();
    return igualas;
}

From source file:appcostal.model.DAO.java

public Iguala obtenerIguala(String idiguala) {
    Iguala iguala = null;/*from  w  ww .j  a  v  a  2 s  .  co  m*/
    SessionFactory s = HibernateUtil.getSessionFactory();
    Session se;
    se = s.openSession();
    Transaction tx = se.beginTransaction();
    Query q = se.createQuery("From Iguala where idiguala='" + idiguala + "'");
    List<Iguala> lista = (List<Iguala>) q.list();
    if (!lista.isEmpty()) {
        iguala = lista.get(0);
    }
    tx.commit();
    se.close();
    return iguala;
}

From source file:appcostal.model.DAO.java

public List<Recorrido> recorridosDisponibles() {
    List<Recorrido> recorridos;
    SessionFactory s = HibernateUtil.getSessionFactory();
    Session se;/*from ww w.  j a  v a  2  s.  com*/
    se = s.openSession();
    Transaction tx = se.beginTransaction();
    Query q = se.createQuery("From Recorrido");
    recorridos = (List<Recorrido>) q.list();
    tx.commit();
    se.close();
    return recorridos;
}

From source file:appcostal.model.DAO.java

public Recorrido obtenerRecorrido(String idrecorrido) {
    Recorrido recorrido = null;/* www .  j  ava 2s .c  om*/
    SessionFactory s = HibernateUtil.getSessionFactory();
    Session se;
    se = s.openSession();
    Transaction tx = se.beginTransaction();
    Query q = se.createQuery("From Recorrido where idrecorrido='" + idrecorrido + "'");
    List<Recorrido> lista = (List<Recorrido>) q.list();
    if (!lista.isEmpty()) {
        recorrido = lista.get(0);
    }
    tx.commit();
    se.close();
    return recorrido;
}

From source file:appcostal.model.DAO.java

public Hermandad obtenerHermandad(String idhermandad) {
    Hermandad hermandad = null;//from w  w  w  .j a  va2  s.co m
    SessionFactory s = HibernateUtil.getSessionFactory();
    Session se;
    se = s.openSession();
    Transaction tx = se.beginTransaction();
    Query q = se.createQuery("From Hermandad where idhermandad='" + idhermandad + "'");
    List<Hermandad> lista = (List<Hermandad>) q.list();
    if (!lista.isEmpty()) {
        hermandad = lista.get(0);
    }
    tx.commit();
    se.close();
    return hermandad;
}

From source file:appcostal.model.DAO.java

public Paso obtenerPaso(String idpaso) {
    Paso paso = null;/* www.ja  v  a  2  s  .  co  m*/
    SessionFactory s = HibernateUtil.getSessionFactory();
    Session se;
    se = s.openSession();
    Transaction tx = se.beginTransaction();
    Query q = se.createQuery("From Paso where idpaso='" + idpaso + "'");
    List<Paso> lista = (List<Paso>) q.list();
    if (!lista.isEmpty()) {
        paso = lista.get(0);
    }
    tx.commit();
    se.close();
    return paso;
}

From source file:appcostal.model.DAO.java

public List<Hermandad> hermandadesDisponibles() {
    List<Hermandad> hermandades;
    SessionFactory s = HibernateUtil.getSessionFactory();
    Session se;/*from www.j  a v a 2  s .c  o  m*/
    se = s.openSession();
    Transaction tx = se.beginTransaction();
    Query q = se.createQuery("From Hermandad");
    hermandades = (List<Hermandad>) q.list();
    tx.commit();
    se.close();
    return hermandades;
}

From source file:appcostal.model.DAO.java

public List<RelHermanoPaso> pasosDeHermano(String dni) {
    List<RelHermanoPaso> pasos;
    SessionFactory s = HibernateUtil.getSessionFactory();
    Session se;//from  www  .  j  a va 2  s.  c o  m
    se = s.openSession();
    Transaction tx = se.beginTransaction();
    Query q = se.createQuery("From RelHermanoPaso where dni='" + dni + "'");
    pasos = (List<RelHermanoPaso>) q.list();
    tx.commit();
    se.close();
    return pasos;
}

From source file:appHibernateSebastianLeonte.Main.java

public static void insertar() {
    SessionFactory session = SessionFactoryUtil.getSessionFactory();
    Session s = session.openSession();
    Transaction transaction = s.beginTransaction();
    System.out.println("Insertando");
    Vuelos vuelos = new Vuelos();
    vuelos.setCodVuelo("AB-BY-4811");
    vuelos.setHoraSalida("02/04/99-14:30");
    vuelos.setDestino("Paris");
    vuelos.setProcedencia("Madrid");
    vuelos.setPlazasFumador(100);//w  w w  . j  a  v a 2 s. co m
    vuelos.setPlazasNoFumador(100);
    vuelos.setPlazasPrimera(100);
    vuelos.setPlazasTurista(100);
    s.save(vuelos);
    transaction.commit();
    s.close();
    session.close();
}

From source file:appHibernateSebastianLeonte.Main.java

public static void eliminar() {
    SessionFactory session = SessionFactoryUtil.getSessionFactory();
    Session s = session.openSession();
    Transaction transaction = s.beginTransaction();
    System.out.println("Elimiando");
    Vuelos vuelos = (Vuelos) s.load(Vuelos.class, (String) "AB-BY-4811");
    s.delete(vuelos);//w  ww  .  j  av a  2s  .c  om
    transaction.commit();
    s.close();
    session.close();
}