Example usage for org.hibernate Query uniqueResult

List of usage examples for org.hibernate Query uniqueResult

Introduction

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

Prototype

R uniqueResult();

Source Link

Document

Convenience method to return a single instance that matches the query, or null if the query returns no results.

Usage

From source file:br.com.sescacre.dao.PessoasDAO.java

public Pessoas pesquisaPessoaPorCPF(String cpf) {
    Session s = HibernateUtil.getSession();
    Query q = s.createQuery("from Pessoas p where p.cpf = :cpf order by p.nome");
    q.setParameter("cpf", cpf);
    Pessoas a = (Pessoas) q.uniqueResult();
    s.close();/*from ww  w.  j  a v  a 2 s  .c  o m*/
    return a;
}

From source file:br.com.sescacre.sisrelat.dao.HistoricoChamadaDao.java

public HistoricoChamada pesquisaChamada(Long programa, Long config, Long ocorrencia, Date mes) {
    Session s = HibernateUtil.getSession();
    Query q = s.createQuery("from HistoricoChamada hc where hc.cdprograma = :programa "
            + "and hc.cdconfig = :config and hc.sqocorrenc = :ocorrencia and hc.mes = :mes");
    q.setParameter("programa", programa);
    q.setParameter("config", config);
    q.setParameter("ocorrencia", ocorrencia);
    q.setParameter("mes", mes);

    return (HistoricoChamada) q.uniqueResult();

}

From source file:br.com.siam.dao.UsuarioDAOHibernate.java

License:Creative Commons License

public Usuario buscarPorLogin(String login) {
    String hql = "select u from Usuario u where u.login = :login";
    Query consulta = this.session.createQuery(hql);
    consulta.setString("login", login);

    //TODO mostrar primeiramente com o list e depois apresentar o uniqueResult
    return (Usuario) consulta.uniqueResult();
}

From source file:br.com.sicva.dao.VacinacaoDao.java

public Integer QtdVacinacao(Integer vac_id, Integer pac_id) {
    session = new FabricaDeConexao().getSessionFactory().openSession();
    Query query = session.createSQLQuery("select count(*) from vacinacao where vacinacao_vacina_id"
            + " = :vac_id and VACINACAO_PAC_ID = :pac_id");
    query.setInteger("vac_id", vac_id);
    query.setInteger("pac_id", pac_id);
    Integer total = ((BigInteger) query.uniqueResult()).intValue();
    session.close();//from w  w  w .  j  a v a2  s . c  o m
    return total;
}

From source file:br.com.sigcopex.dao.CursoDAO.java

public Curso buscarPorCodigo(Long codigo) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    Curso curso = null;/*from w w  w.  ja v  a  2  s  .com*/

    try {
        Query consulta = sessao.getNamedQuery("Curso.buscarPorCodigo");
        consulta.setLong("codigo", codigo);

        curso = (Curso) consulta.uniqueResult();
    } catch (RuntimeException ex) {
        throw ex;
    } finally {
        sessao.close();
    }

    return curso;
}

From source file:br.com.sigcopex.dao.DisciplinaDAO.java

public Disciplina buscarPorCodigo(Long codigo) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    Disciplina disciplina = null;/*from  w w w  .j av  a  2  s . c om*/

    try {
        Query consulta = sessao.getNamedQuery("Disciplina.buscarPorCodigo");
        consulta.setLong("codigo", codigo);

        disciplina = (Disciplina) consulta.uniqueResult();
    } catch (RuntimeException ex) {
        throw ex;
    } finally {
        sessao.close();
    }

    return disciplina;
}

From source file:br.com.sigcopex.dao.ExtensaoDAO.java

public Extensao buscarPorCodigo(Long codigo) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    Extensao extensao = null;//w w w  .  ja v  a  2s . c  o m

    try {
        Query consulta = sessao.getNamedQuery("Extensao.buscarPorCodigo");
        consulta.setLong("codigo", codigo);

        extensao = (Extensao) consulta.uniqueResult();
    } catch (RuntimeException ex) {
        throw ex;
    } finally {
        sessao.close();
    }

    return extensao;
}

From source file:br.com.sigcopex.dao.MonitoriaDAO.java

public Monitoria buscarPorCodigo(Long codigo) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    Monitoria curso = null;//from   w  ww  . ja  v a  2s .c om

    try {

        Query consulta = sessao.getNamedQuery("Monitoria.buscarPorCodigo");
        consulta.setLong("codigo", codigo);

        curso = (Monitoria) consulta.uniqueResult();

    }

    catch (RuntimeException ex) {
        throw ex;
    } finally {
        sessao.close();
    }

    return curso;

}

From source file:br.com.sigcopex.dao.ProfessorDAO.java

public Professor buscarPorCodigo(Long codigo) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    Professor professor = null;/*from  w w w.j  a  va2 s  . c o m*/

    try {
        Query consulta = sessao.getNamedQuery("Professor.buscarPorCodigo");
        consulta.setLong("codigo", codigo);

        professor = (Professor) consulta.uniqueResult();
    } catch (RuntimeException ex) {
        throw ex;
    } finally {
        sessao.close();
    }

    return professor;
}

From source file:br.com.sigcopex.dao.TermoAutorizacaoExtensaoDAO.java

public TermoAutorizacaoExtensao buscarPorCodigo(Long codigo) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    TermoAutorizacaoExtensao termoAutorizacaoExtensao = null;

    try {//www.  j a  va  2  s .  co m

        Query consulta = sessao.getNamedQuery("TermoAutorizacaoExtensao.buscarPorCodigo");
        consulta.setLong("codigo", codigo);

        termoAutorizacaoExtensao = (TermoAutorizacaoExtensao) consulta.uniqueResult();

    }

    catch (RuntimeException ex) {
        throw ex;
    } finally {
        sessao.close();
    }

    return termoAutorizacaoExtensao;

}