Example usage for org.hibernate Query list

List of usage examples for org.hibernate Query list

Introduction

In this page you can find the example usage for org.hibernate Query list.

Prototype

List<R> list();

Source Link

Document

Return the query results as a List.

Usage

From source file:appcostal.model.DAO.java

public Paso obtenerPaso(String idpaso) {
    Paso paso = null;//  www .j  ava2  s .  c om
    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   ww  w .  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 . co  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 consulta() {
    SessionFactory session = SessionFactoryUtil.getSessionFactory();
    Session s = session.openSession();//  w w  w.java  2 s. c om
    Transaction transaction = s.beginTransaction();
    System.out.println("Modificando");
    Vuelos vuelo = new Vuelos();
    Query q = s.createQuery("from Vuelos where Destino='BARCELONA' or Destino='MADRID'");
    List<Vuelos> listaVuelo = q.list();
    Iterator<Vuelos> iter = listaVuelo.iterator();
    while (iter.hasNext()) {
        vuelo = (Vuelos) iter.next();
        System.out.println("PROCEDENCIA: " + vuelo.getProcedencia() + "\t");
        System.out.println("DESTINO: " + vuelo.getDestino() + "\t");
        System.out.println("HORA DE SALIDA: " + vuelo.getHoraSalida());
    }
    s.close();
    session.close();
}

From source file:ar.com.hibernate.dao.Dao.java

public <T> List<T> obtenerTodos(Class<T> clazz) {
    Session s = SessionManager.getSessionFactory().openSession();
    Query q = s.createQuery("from " + clazz.getName());
    List<T> entities = q.list();
    s.close();//from  w w w . j  a  va2s .  c o  m
    return entities;
}

From source file:aseguradora.HospitalVentana.java

public void cargarHospital() {
    try {/* w w  w. j  a  v  a 2  s.c o  m*/
        String[] columnNames = new String[3];
        DefaultTableModel model = new DefaultTableModel(columnNames, 0);

        Session session = sesion.openSession();

        Hospital hos = new Hospital();
        Query cons = session.createQuery("from pojo.Hospital");
        List<Hospital> lista = cons.list();
        Iterator<Hospital> iter = lista.iterator();

        while (iter.hasNext()) {
            hos = (Hospital) iter.next();
            Hibernate.initialize(hos.getCodH());
            Vector row = new Vector();
            row.add(hos.getCodH());
            row.add(hos.getNH());
            row.add(hos.getNumC());
            model.addRow(row);
        }

        tablaHospital.setModel(model);
        session.close();
    } catch (HibernateException e) {
        e.printStackTrace();
        if (e.getMessage().contains("" + TABLA_NO_ENCONTRADA)) {
            JOptionPane.showMessageDialog(rootPane,
                    "Tabla no encontrada. Pongase en contacto con el administrador.");
        }
    }
}

From source file:aseguradora.HospitalVentana.java

private void buscarHospital(String nombre) {

    Session session = sesion.openSession();
    Hospital hos;/*ww  w. j av  a2s . c om*/
    Query cons = session.createQuery("from pojo.Hospital as hos " + "where upper(hos.NH) LIKE ?");
    cons.setString(0, "%" + nombre.toUpperCase() + "%");
    List<Hospital> lista = cons.list();
    DefaultTableModel model = (DefaultTableModel) tablaHospital.getModel();
    if (!lista.isEmpty()) {
        model.getDataVector().removeAllElements();
        model.fireTableDataChanged();
        Iterator<Hospital> iter = lista.iterator();
        while (iter.hasNext()) {
            hos = (Hospital) iter.next();
            Hibernate.initialize(hos.getCodH());
            Vector row = new Vector();
            row.add(hos.getCodH());
            row.add(hos.getNH());
            row.add(hos.getNumC());
            model.addRow(row);
        }
        tablaHospital.setModel(model);
        session.close();
    } else {
        model.getDataVector().removeAllElements();
        model.fireTableDataChanged();
        JOptionPane.showMessageDialog(null, "No hay resultados para su bsqueda", "Informacin",
                JOptionPane.ERROR_MESSAGE);
        cargarHospital();
    }

}

From source file:aseguradora.MedicoVentana.java

public void cargarMedico() {
    try {//from ww w.  j a  v a  2s .co  m
        String[] columnNames = new String[3];
        DefaultTableModel model = new DefaultTableModel(columnNames, 0);

        Session session = sesion.openSession();

        Medico med = new Medico();
        Query cons = session.createQuery("from pojo.Medico");
        List<Medico> lista = cons.list();
        Iterator<Medico> iter = lista.iterator();

        while (iter.hasNext()) {
            med = (Medico) iter.next();
            Hibernate.initialize(med.getHospital());
            Vector row = new Vector();
            row.add(med.getCodM());
            row.add(med.getNM());
            row.add(med.getHospital().getCodH());
            model.addRow(row);
        }

        tablaMedico.setModel(model);
        session.close();

    } catch (JDBCException e) {
        e.printStackTrace();
        if (e.getErrorCode() == TABLA_NO_ENCONTRADA) {
            JOptionPane.showMessageDialog(rootPane,
                    "Tabla no encontrada. Pongase en contacto con el administrador.");
        }
    }
}

From source file:aseguradora.MedicoVentana.java

private void buscarMedico(String nombre) {

    Session session = sesion.openSession();
    Medico me;/*from  w  w  w .j  a  v a2s. c o  m*/
    Query cons = session.createQuery("from pojo.Medico as me " + "where upper(me.NM) LIKE ?");
    cons.setString(0, "%" + nombre.toUpperCase() + "%");
    List<Medico> lista = cons.list();
    DefaultTableModel model = (DefaultTableModel) tablaMedico.getModel();
    if (!lista.isEmpty()) {
        model.getDataVector().removeAllElements();
        model.fireTableDataChanged();
        Iterator<Medico> iter = lista.iterator();
        while (iter.hasNext()) {
            me = (Medico) iter.next();
            Hibernate.initialize(me.getHospital());
            Vector row = new Vector();
            row.add(me.getCodM());
            row.add(me.getHospital().getCodH());
            row.add(me.getNM());
            model.addRow(row);
        }
        tablaMedico.setModel(model);
        session.close();
    } else {
        model.getDataVector().removeAllElements();
        model.fireTableDataChanged();
        JOptionPane.showMessageDialog(null, "No hay resultados para su bsqueda", "Informacin",
                JOptionPane.ERROR_MESSAGE);
        cargarMedico();
    }

}

From source file:aseguradora.VistaVentana.java

public void cargarVista() {
    try {//from  w  w w  . ja v a2s.c o m
        String[] columnNames = { "Cod. Poliza", "Datos Poliza", "Num", "Nombre Asegurado", "FN" };
        DefaultTableModel model = new DefaultTableModel(columnNames, 0);

        Session session = sesion.openSession();

        PolizasAsegurados pa = new PolizasAsegurados();
        Query cons = session.createQuery("from pojo.PolizasAsegurados");
        List<PolizasAsegurados> lista = cons.list();
        Iterator<PolizasAsegurados> iter = lista.iterator();

        while (iter.hasNext()) {
            pa = (PolizasAsegurados) iter.next();
            Hibernate.initialize(pa.getId());
            Vector row = new Vector();
            row.add(pa.getId().getCodP());
            row.add(pa.getId().getDatosP());
            row.add(pa.getId().getNum());
            row.add(pa.getId().getNa());
            row.add(formatDate(pa.getId().getFn().toString()));
            model.addRow(row);
        }

        tablaVista.setModel(model);
        session.close();

    } catch (JDBCException e) {
        e.printStackTrace();
        if (e.getErrorCode() == TABLA_NO_ENCONTRADA) {
            JOptionPane.showMessageDialog(rootPane,
                    "Tabla no encontrada. Pongase en contacto con el administrador.");
        }
    }
}