Example usage for org.hibernate SQLQuery addEntity

List of usage examples for org.hibernate SQLQuery addEntity

Introduction

In this page you can find the example usage for org.hibernate SQLQuery addEntity.

Prototype

SQLQuery<T> addEntity(Class entityType);

Source Link

Document

Declare a "root" entity, without specifying an alias.

Usage

From source file:com.sistcontable.dao.EstadoDAO.java

public void searchEstadoByID(String id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from   w w  w.  j  av  a 2s  .  c  o m*/
    List<Estado> lista = new ArrayList();
    try {
        String query = "select * from estado where ID_ESTADO=:idEstado";
        SQLQuery sqlQuery = session.createSQLQuery(query);
        sqlQuery.addEntity(Estado.class);
        sqlQuery.setParameter("idEstado", id);
        List result = sqlQuery.list();

        for (int i = 0; i < result.size(); i++) {
            System.out.println("id: ");
            Estado estado = (Estado) result.get(i);
            System.out.println("idEstado: " + estado.getIdEstado());
            System.out.println("nombreEstado: " + estado.getNombreEstado());
            System.out.println("disponibilidad: " + estado.getDisponibilidad());
        }
    } catch (Exception e) {
        System.out.println("ERROR " + e);
        lista = null;
    } finally {
        session.close();
    }
}

From source file:com.sistcontable.dao.EstadoDAO.java

public Estado obtenerEstadoByID(String id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();// w w w .  j  a va2s. c  o m
    List<Estado> lista = new ArrayList();
    try {
        String query = "select * from estado where ID_ESTADO=:idEstado";
        SQLQuery sqlQuery = session.createSQLQuery(query);
        sqlQuery.addEntity(Estado.class);
        sqlQuery.setParameter("idEstado", id);
        List result = sqlQuery.list();

        for (int i = 0; i < result.size(); i++) {
            System.out.println("id: ");
            Estado estado = (Estado) result.get(i);
            System.out.println("idEstado: " + estado.getIdEstado());
            System.out.println("nombreEstado: " + estado.getNombreEstado());
            System.out.println("disponibilidad: " + estado.getDisponibilidad());
        }
        return (Estado) result.get(0);
    } catch (Exception e) {
        System.out.println("ERROR " + e);
        lista = null;
        return null;
    } finally {
        session.close();
    }
}

From source file:com.sistcontable.dao.EstadoDAO.java

public List<Estado> searchAllEstados() {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from  w  ww.  ja  v  a2  s. co m*/
    List<Estado> lista = new ArrayList();
    try {
        String query = "select * from estado";
        SQLQuery sqlQuery = session.createSQLQuery(query);
        sqlQuery.addEntity(Estado.class);
        lista = sqlQuery.list();

        for (int i = 0; i < lista.size(); i++) {
            System.out.println("-------------------------------------------------");
            System.out.println("idEstado: " + lista.get(i).getIdEstado());
            System.out.println("nombreEstado: " + lista.get(i).getNombreEstado());
            System.out.println("disponibilidad: " + lista.get(i).getDisponibilidad());

        }

    } catch (Exception e) {
        System.out.println("ERROR " + e);
        lista = null;
    } finally {
        session.close();
    }
    return lista;
}

From source file:com.sistcontable.dao.PersonaDAO.java

public List<Persona> searchAllPersona(String opcion) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from  www .j a  v a2s .c o  m*/
    List<Persona> lista = new ArrayList();
    try {
        String query = "select * from persona where es_Historico= :opcion";
        SQLQuery sqlQuery = session.createSQLQuery(query);
        sqlQuery.addEntity(Persona.class).setString("opcion", opcion);

        lista = sqlQuery.list();

    } catch (Exception e) {
        System.out.println("ERROR " + e);
        lista = null;
    } finally {
        session.close();
    }
    return lista;
}

From source file:com.sistcontable.dao.PersonaDAO.java

public List<Municipio> searchAllMunicipio() {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();// w  ww . j  a  va2s  .  c o  m
    List<Municipio> lista = new ArrayList();
    try {
        String query = "select * from municipio";
        SQLQuery sqlQuery = session.createSQLQuery(query);
        sqlQuery.addEntity(Municipio.class);
        lista = sqlQuery.list();
    } catch (Exception e) {
        System.out.println("ERROR " + e);
        lista = null;
    } finally {
        session.close();
    }
    return lista;
}

From source file:com.sistcontable.dao.RubroDAO.java

public void searchRubroByID(String id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from  ww w. j  a  v a2 s .  c o  m*/
    List<Rubro> lista = new ArrayList();
    try {
        String query = "select * from rubro where ID_RUBRO=:idRubro";
        SQLQuery sqlQuery = session.createSQLQuery(query);
        sqlQuery.addEntity(Rubro.class);
        sqlQuery.setParameter("idRubro", id);
        List result = sqlQuery.list();

        for (int i = 0; i < result.size(); i++) {
            System.out.println("id: ");
            Rubro rubro = (Rubro) result.get(i);

            System.out.println("idRubro: " + rubro.getIdRubro());
            System.out.println("nombreRubro: " + rubro.getNombreRubro());
            System.out.println("tipoRubro: " + rubro.getTipoRubro());

        }
    } catch (Exception e) {
        System.out.println("ERROR " + e);
        lista = null;
    } finally {
        session.close();
    }
}

From source file:com.sistcontable.dao.RubroDAO.java

public Rubro obtenerRubroByID(String id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from  www. j av a 2s .  c  o m*/
    List<Rubro> lista = new ArrayList();
    try {
        String query = "select * from rubro where ID_RUBRO=:idRubro";
        SQLQuery sqlQuery = session.createSQLQuery(query);
        sqlQuery.addEntity(Rubro.class);
        sqlQuery.setParameter("idRubro", id);
        List result = sqlQuery.list();

        for (int i = 0; i < result.size(); i++) {
            System.out.println("id: ");
            Rubro rubro = (Rubro) result.get(i);

            System.out.println("idRubro: " + rubro.getIdRubro());
            System.out.println("nombreRubro: " + rubro.getNombreRubro());
            System.out.println("tipoRubro: " + rubro.getTipoRubro());

        }

        return (Rubro) result.get(0);
    } catch (Exception e) {
        System.out.println("ERROR " + e);
        lista = null;
        return null;
    } finally {
        session.close();
    }
}

From source file:com.sistcontable.dao.RubroDAO.java

public List<Rubro> searchAllRubros() {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from ww w  .j av  a  2s  .  co  m*/
    List<Rubro> lista = new ArrayList();
    try {
        String query = "select * from rubro";
        SQLQuery sqlQuery = session.createSQLQuery(query);
        sqlQuery.addEntity(Rubro.class);
        lista = sqlQuery.list();

        for (int i = 0; i < lista.size(); i++) {
            System.out.println("-------------------------------------------------");
            System.out.println("idRubro: " + lista.get(i).getIdRubro());
            System.out.println("nombreRubro: " + lista.get(i).getNombreRubro());
            System.out.println("tipoRubro: " + lista.get(i).getTipoRubro());

        }

    } catch (Exception e) {
        System.out.println("ERROR " + e);
        lista = null;
    } finally {
        session.close();
    }
    return lista;
}

From source file:com.sistcontable.dao.TelefonoDAO.java

public List<Telefono> searchAllTelefono() {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from   w  w  w .j  a  va 2 s. c  o m*/
    List<Telefono> lista = new ArrayList();
    try {
        String query = "select * from telefono";
        SQLQuery sqlQuery = session.createSQLQuery(query);
        sqlQuery.addEntity(Telefono.class);

        lista = sqlQuery.list();

    } catch (Exception e) {
        System.out.println("ERROR " + e);
        lista = null;
    } finally {
        session.close();
    }
    return lista;
}

From source file:com.sistcontable.dao.TransaccionDAO.java

public List<Cuenta> searchAllCuenta() {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from w w w  .java 2s .  c  om*/
    List<Cuenta> lista = new ArrayList();
    try {
        String query = "select  *  from cuenta";
        SQLQuery sqlQuery = session.createSQLQuery(query);
        sqlQuery.addEntity(Cuenta.class);
        lista = sqlQuery.list();
    } catch (Exception e) {
        System.out.println("ERROR " + e);
        lista = null;
    } finally {
        session.close();
    }
    return lista;
}