Example usage for org.hibernate Session createQuery

List of usage examples for org.hibernate Session createQuery

Introduction

In this page you can find the example usage for org.hibernate Session createQuery.

Prototype

@Override
    org.hibernate.query.Query createQuery(CriteriaDelete deleteQuery);

Source Link

Usage

From source file:Beans.Asistencia.java

public String NombreProyecto(int cod) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction t = session.beginTransaction();
        Proyectos p = new Proyectos();
        try {/*  ww  w.j  ava2  s. c o m*/
            p = (Proyectos) session.createQuery("select p from Proyectos p where" + " p.codigoProyecto=" + cod)
                    .uniqueResult();
        } catch (Exception ex) {
            System.out.println("Error NombreProyecto " + ex.toString());
        }
        return p.getNombre();
    }

From source file:Beans.Asistencia.java

public void cargarDatosEstudiante() {
        System.out.println("----------------------");
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction t = session.beginTransaction();
        ModeloAsesoria M = new ModeloAsesoria();
        ArrayList<Usuario> p = new ArrayList();
        M = (ModeloAsesoria) FacesContext.getCurrentInstance().getExternalContext().getSessionMap()
                .get("ModeloASesoria");
        System.out.println("--- cod: " + M.getCodigo_ase());
        if (FacesContext.getCurrentInstance().getExternalContext().getSessionMap()
                .get("lista_estudiante") != null) {
            lista_estu = (ArrayList) FacesContext.getCurrentInstance().getExternalContext().getSessionMap()
                    .get("lista_estudiante");
            for (int i = 0; i < lista_estu.size(); i++) {
                System.out.println("-- ::: " + lista_estu.get(i));
            }// w w  w  . j  av a 2 s .c  om
        } else {
            lista_estu.clear();

            try {
                p = (ArrayList) session.createQuery("select U from Usuario U INNER JOIN "
                        + "U.asistentes A INNER JOIN A.asesoria S" + " where S.codAsesoria=" + M.getCodigo_ase())
                        .list();
                t.commit();
                Usuario temp = null;
                for (int i = 0; i < p.size(); i++) {
                    temp = (Usuario) p.get(i);
                    System.out.println("entro pege " + temp.getPegeId());

                    lista_estu.add(new Estudiante(false, "", "", "", "" + temp.getPegeId()));
                }
                TraerDatosPersonales();
                for (int i = 0; i < lista_estu.size(); i++) {
                    System.out.println("-- " + lista_estu.get(i));
                }
            } catch (Exception ex) {
                System.out.println("Error CargarDatoEstudiante " + ex.toString());
            }
        }

    }

From source file:beans.BackList.java

/**
 * Creates a new instance of BookList//from  ww w  . j av a 2  s  .co m
 */
public BackList() {
    Session session = hibernate.HibernateUtil.getSessionFactory().openSession();
    backList = session.createQuery("FROM Book WHERE available = 0").list();
    session.close();
}

From source file:beans.BookList.java

public void fillBook() {
    Session session = hibernate.HibernateUtil.getSessionFactory().openSession();
    bookList = session.createQuery("FROM Book WHERE available = 1").list();
    session.close();//from  www . ja  va 2s  .  c om
}

From source file:Beans.CalendarioAsesoriaUpdate.java

public void traerDetalle(Asesoria ase) throws ClassNotFoundException {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    Transaction t = session.beginTransaction();
    System.out.println("Entroo detalle");

    //        Conecion_postgres1.conectar();
    //        Conecion_postgres1.ejecuteQuery("select  detalle_asesoria.descripcion \n"
    //                + "from asesoria,detalle_asesoria\n"
    //                + "where\n"
    //                + " asesoria.cod_asesoria=detalle_asesoria.cod_asesoria\n"
    //                + "and asesoria.cod_asesoria=" + ase.getCodAsesoria() + "");
    ArrayList<DetalleAsesoria> lisD = new ArrayList();
    ArrayList<String> detalles = new ArrayList();
    try {/*from w  w  w . ja  va2  s .  com*/
        lisD = (ArrayList) session.createQuery(
                "select D from Asesoria A inner join " + " A.detalleAsesorias D where A.fechaAsesoria<='"
                        + ase.getFechaAsesoria() + "' " + " and A.codigoProyecto=" + ase.getCodigoProyecto())
                .list();
        detalle_Asesoria = lisD.get(lisD.size() - 1).getDescripcion();
        System.out.println("size : " + lisD.get(lisD.size() - 1).getCodDetalle());
        //            while (Conecion_postgres1.rs.next()) {
        //                detalles.add(Conecion_postgres1.rs.getString(1));
        //            }
        //            System.out.println("detalle : " + detalles.get(0) + " size:" + detalles.size());
        //            detalle_Asesoria = detalles.get(0);
        //            Conecion_postgres1.cerrarConexion();
        t.commit();
    } catch (Exception ex) {
        System.out.println("Error traerDetalle " + ex.toString());
    }
}

From source file:Beans.CalendarioAsesoriaUpdate.java

public void traerTareas(Asesoria ase) throws ClassNotFoundException {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    Transaction t = session.beginTransaction();
    System.out.println("Entroo Tareas");

    ArrayList<Tareas> listT = new ArrayList();
    //        ArrayList<String> detalles = new ArrayList();
    ArrayList<Asesoria> listA = new ArrayList();
    list_tareas.clear();//from w  ww  .jav  a  2 s . c  o  m
    try {
        listA = (ArrayList) session.createQuery("select A from Asesoria A where " + "A.fechaAsesoria<'"
                + ase.getFechaAsesoria() + "' " + "and A.codigoProyecto=" + ase.getCodigoProyecto() + " "
                + " order by A.fechaAsesoria DESC").list();

        for (Asesoria a : listA) {
            System.out.println("---- : " + a.getFechaAsesoria());
        }

        System.out.println("size Asesoria : " + listA.size());
        listT = (ArrayList) session.createQuery("select t from Asesoria A " + " inner join A.tareases t where "
                + "A.codAsesoria=" + listA.get(0).getCodAsesoria()).list();
        System.out.println("Size tarea : " + listT.size() + " cod : " + listA.get(0).getCodAsesoria());
        for (Tareas ta : listT) {
            System.out.println("----");
            list_tareas.add(new ModeloAsesoria(ta.getResponsable(), ta.getTarea()));
        }
        t.commit();

    } catch (Exception ex) {
        System.out.println("Error tareas " + ex.toString());
    }

    //        Conecion_postgres1.conectar();
    //        list_tareas.clear();
    //        System.out.println("entro a tareas");
    //        Conecion_postgres1.ejecuteQuery("select  tareas.* \n"
    //                + "from asesoria,tareas\n"
    //                + "where\n"
    //                + " asesoria.cod_asesoria=tareas.cod_asesoria\n"
    //                + "and asesoria.cod_asesoria=" + cod_ase);
    //
    //        try {
    //            while (Conecion_postgres1.rs.next()) {
    //                list_tareas.add(new ModeloAsesoria(Conecion_postgres1.rs.getString(2), Conecion_postgres1.rs.getString(3)));
    //            }
    //            System.out.println("tamao tareas " + list_tareas.size());
    //            Conecion_postgres1.cerrarConexion();
    //        } catch (Exception ex) {
    //            System.out.println("Error Tareas " + ex.toString());
    //        }
}

From source file:Beans.CargarArchivos.java

public void cargar_tipo() {
    System.out.println("Entr");
    tipo.clear();/*w w  w .j  a v  a 2  s. co m*/
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    Transaction t = session.beginTransaction();
    try {
        tipo = (ArrayList) session.createQuery("from TipoProyecto").list();
        t.commit();
    } catch (Exception ex) {
        System.out.println("Error " + ex.toString());
    }

}

From source file:beans.Cart.java

/**
 * Find the user from the database according to the given username and
 * password and set into the client field.
 *//*w ww .  jav  a2  s .c om*/
public void findClient() {
    if (loginData.getUsername() != null || loginData.getPassword() != null) {
        Session session = hibernate.HibernateUtil.getSessionFactory().openSession();
        List<Client> clients;
        Query query = session.createQuery("FROM Client WHERE username =:username AND password =:password");
        query.setParameter("username", loginData.getUsername());
        query.setParameter("password", loginData.getPassword());
        clients = query.list();
        if (clients.size() > 0) {
            client = clients.get(0);
        }
        session.close();
    }
}

From source file:beans.Catalog.java

private void queryFilmsFromDB() {
    Session session = hibernate.HibernateUtil.getSessionFactory().openSession();
    fullFilmList = session.createQuery("FROM Film").list();
    filteredFilmList = new ArrayList<Film>();
    for (Film f : fullFilmList) {
        filteredFilmList.add(f);/*  w w  w . j a  v a2  s . c o m*/
    }
    session.close();
}

From source file:beans.Catalog.java

private void queryDatastoreFromDB() {
    Session session = hibernate.HibernateUtil.getSessionFactory().openSession();
    datastoreList = session.createQuery("FROM Datastore").list();
    session.close();/*w ww .j  a  v a  2s .com*/
    datastoreCombo.clear();
    for (Datastore ds : datastoreList) {
        datastoreCombo.add(ds.toString());
    }
}