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:dao.CompoundDao.java

public List<Compound> searchCompoundByName(String str) {
    List<Compound> objects = null;
    SQLQuery sqlq = null;

    try {//ww w.  jav a  2  s.c  om
        tx = session.beginTransaction();
        sqlq = session.createSQLQuery("call searchCompoundByName(:str)");
        sqlq.setString("str", str);
        objects = sqlq.addEntity(Compound.class).list();
        tx.commit();
    } catch (HibernateException e) {
        tx.rollback();
    }
    return objects;
}

From source file:dao.CompoundDao.java

public List<Compound> searchCompoundByFomula(String str) {
    List<Compound> objects = null;
    SQLQuery sqlq = null;

    try {/*  w w  w  .  java 2s .  c om*/
        tx = session.beginTransaction();
        sqlq = session.createSQLQuery("call searchCompoundByFomula(:str)");
        sqlq.setString("str", str);
        List<Compound> list = objects = sqlq.addEntity(Compound.class).list();
        tx.commit();
    } catch (HibernateException e) {
        tx.rollback();
    }
    return objects;
}

From source file:dao.CompoundDao.java

public List<Compound> findCompoundById(String str) {
    SQLQuery sqlq = null;
    List<Compound> objects = null;

    try {// w  w w. j a v  a  2  s.c  om
        tx = session.beginTransaction();
        sqlq = session.createSQLQuery("SELECT * FROM Compound  WHERE  Compound.idCompound=:str");
        sqlq.setString("str", str);
        objects = sqlq.addEntity(Compound.class).list();
        tx.commit();

    } catch (HibernateException e) {
        tx.rollback();
    }
    return objects;

}

From source file:dao.EnterpriseDao.java

public List<Enterprise> searchEnterpriseByIdCity(String str) {
    List<Enterprise> objects = null;
    SQLQuery sqlq = null;

    try {/*from   w ww.j  av  a 2 s  . co  m*/
        tx = session.beginTransaction();
        sqlq = session.createSQLQuery("select * from Enterprise where idCity=(:str)");
        sqlq.setString("str", str);
        objects = sqlq.addEntity(Enterprise.class).list();
        tx.commit();
    } catch (HibernateException e) {
        tx.rollback();
    }
    return objects;
}

From source file:DAO.FilialDao.java

public List<Filial> pesqView() {
    List<Filial> listaFilial = new ArrayList();
    try {//from  w ww. jav a2  s .c  om
        Session sessao = HibernateUtil.getSessionFactory().openSession();
        sessao.beginTransaction();

        SQLQuery q = sessao.createSQLQuery("Select * from PESQFILIAL");
        q.addEntity(Filial.class);
        List<Filial> resultado = q.list();
        for (Filial a : resultado) {
            Filial filial = (Filial) a;
            listaFilial.add(filial);
        }
        sessao.getTransaction().commit();
        return listaFilial;

    } catch (Exception e) {
        Login.log.info("Erro ao pesquisar filial(pesqView): " + e);
        return null;
    }
}

From source file:dao.MessageDao.java

public List<Message> getMessageByUserID(String str) {
    List<Message> objects = null;
    SQLQuery sqlq = null;

    try {/*from   ww  w .  java 2 s  .  co  m*/
        tx = session.beginTransaction();
        sqlq = session.createSQLQuery("select * from Message where Message.receiver=(:str)");
        sqlq.setString("str", str);
        objects = sqlq.addEntity(Message.class).list();
        tx.commit();
    } catch (HibernateException e) {
        tx.rollback();
    }
    return objects;
}

From source file:DAO.OrcamentoDao.java

public List<Orcamento> pesqView() {
    List<Orcamento> listaOrcamento = new ArrayList();
    try {//from   w w  w.j  a v  a 2  s.c  om
        Session sessao = HibernateUtil.getSessionFactory().openSession();
        sessao.beginTransaction();

        SQLQuery q = sessao.createSQLQuery("Select * from PESQORCAMENTO");
        q.addEntity(Orcamento.class);
        List<Orcamento> resultado = q.list();
        for (Orcamento a : resultado) {
            Orcamento orcamento = (Orcamento) a;
            listaOrcamento.add(orcamento);
        }
        sessao.getTransaction().commit();
        return listaOrcamento;

    } catch (Exception e) {
        Login.log.info("Erro ao pesquisar Orcamento(pesqView): " + e);
        return null;
    }
}

From source file:DAO.OrcamentoPEDao.java

public List<OrcamentoProdutoestoque> pesqOrcPE(int cod) {
    List<OrcamentoProdutoestoque> listaOPE = new ArrayList();
    try {/*  w w w. j  ava  2 s  .c o m*/
        Session sessao = HibernateUtil.getSessionFactory().openSession();
        sessao.beginTransaction();

        SQLQuery q = sessao.createSQLQuery(
                "SELECT OPE.PRODUTOESTOQUE_PRODUTOS_CODIGO, OPE.PRODUTOESTOQUE_CODIGOESTOQUE,PRODUTOS.DESCRICAO,OPE.ORCAMENTO_CODIGO,OPE.QTD "
                        + "FROM ORCAMENTO_PRODUTOESTOQUE OPE "
                        + "LEFT OUTER JOIN PRODUTOS ON PRODUTOS.CODIGO = OPE.PRODUTOESTOQUE_PRODUTOS_CODIGO "
                        + "WHERE OPE.ORCAMENTO_CODIGO = " + cod);

        q.addEntity(OrcamentoProdutoestoque.class);

        List<OrcamentoProdutoestoque> resultado = q.list();

        for (OrcamentoProdutoestoque a : resultado) {
            OrcamentoProdutoestoque orcpe = (OrcamentoProdutoestoque) a;
            listaOPE.add(orcpe);
        }
        sessao.getTransaction().commit();
        return listaOPE;

    } catch (Exception e) {
        Login.log.info("Erro ao pesquisar OrcamentoProdutoEstoque(pesqOrcPE): " + e);
        return null;
    }
}

From source file:dao.ParametrDao.java

public List<Parametr> getParamsFromCat(Long catId) {
    String sql = "select p.* from param_category_link l left join parametr p on l.parametr_id=p.parametr_id where l.category_id=:catId";
    SQLQuery query = getCurrentSession().createSQLQuery(sql);
    query.addEntity(Parametr.class);
    query.setParameter("catId", catId);
    return query.list();
}

From source file:dao.PatientsDao.java

public List<Patients> searchPatientsByName(String str) {
    List<Patients> objects = null;
    SQLQuery sqlq = null;

    try {//from w ww.ja v  a 2  s.  c  o m
        tx = session.beginTransaction();
        sqlq = session.createSQLQuery("call searchPatientsByLastName(:str)");
        sqlq.setString("str", str);
        objects = sqlq.addEntity(Patients.class).list();
        tx.commit();
    } catch (HibernateException e) {
        tx.rollback();
    }
    return objects;
}