Example usage for org.hibernate Query setString

List of usage examples for org.hibernate Query setString

Introduction

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

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setString(String name, String val) 

Source Link

Document

Bind a named String-valued parameter.

Usage

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

public Vacinas consultarPorNome(String nome) {
    session = new HibernateUtil().getSessionFactory().openSession();
    Query query = session.createSQLQuery("SELECT * FROM vacinas" + " WHERE vacinas_descricao = :nome")
            .addEntity(Vacinas.class);
    query.setString("nome", nome);
    listarVacinas = query.list();//from   w  ww.  ja v a  2s .c  o m
    session.close();
    if (listarVacinas.isEmpty()) {
        return null;
    } else {
        return listarVacinas.get(0);
    }
}

From source file:br.edu.ifes.sr.dw.persistencia.ClienteDaoHibernate.java

@Override
public Cliente buscar(String cpf) {
    session.getTransaction().begin();/*from w  ww.  j  av a  2  s  .  com*/
    String hql = "select c from Cliente c where c.cpf = :cpf";
    Query consulta = session.createQuery(hql);
    consulta.setString("cpf", cpf);
    Cliente cliente = (Cliente) consulta.uniqueResult();
    session.getTransaction().commit();
    session.close();
    return cliente;
}

From source file:br.edu.ifes.sr.dw.persistencia.ClienteDaoHibernate.java

@Override
public Cliente buscarPorEmail(String email) {
    session.getTransaction().begin();//from   w w  w  .j  ava2s  .  c  o  m
    String hql = "select c from Cliente c where c.email = :email";
    Query consulta = session.createQuery(hql);
    consulta.setString("email", email);
    Cliente cliente = (Cliente) consulta.uniqueResult();
    session.getTransaction().commit();
    session.close();
    return cliente;
}

From source file:br.edu.ifes.sr.dw.persistencia.ClienteDaoHibernate.java

@Override
public Cliente validarLogin(String email, String senha) {
    session.getTransaction().begin();/*from  ww w. j a  v a 2 s  .co  m*/
    String hql = "select c from Cliente c where c.email = :email and c.senha = :senha ";
    Query consulta = session.createQuery(hql);
    consulta.setString("email", email);
    consulta.setString("senha", senha);
    Cliente cliente = (Cliente) consulta.uniqueResult();
    session.getTransaction().commit();
    session.close();
    return cliente;
}

From source file:br.edu.ifes.sr.dw.persistencia.ComprasDaoHibernate.java

@Override
public List<Compra> listarCliente(String email) {
    session.getTransaction().begin();//from w  w w  . j  a  va 2s .  c  om
    String hql = "select c from Compra c inner join c.cliente cl where cl.email = :email";
    Query consulta = session.createQuery(hql);
    consulta.setString("email", email);
    List<Compra> lista = (List<Compra>) consulta.list();
    session.getTransaction().commit();
    session.close();
    return lista;
}

From source file:br.edu.ifes.sr.dw.persistencia.CupomDaoHibernate.java

@Override
public List<Cupom> buscarPorInstituicao(String email) {
    session.getTransaction().begin();/*w w  w  . j a  v  a 2 s  . c  o m*/
    String hql = "select c from Cupom c inner join c.instituicao i where i.email = :email";
    Query consulta = session.createQuery(hql);
    consulta.setString("email", email);
    List<Cupom> cupons = (List<Cupom>) consulta.list();
    session.getTransaction().commit();
    session.close();
    return cupons;
}

From source file:br.edu.ifes.sr.dw.persistencia.CupomDaoHibernate.java

@Override
public Cupom buscarCodigoCpfCliente(String codigo, String cpf) {
    session.getTransaction().begin();// w w  w.  j  a v a 2 s  .  c  o m
    String hql = "select c from Cupom c inner join c.cliente cl where c.codigo = :codigo and cl.cpf = :cpf";
    Query consulta = session.createQuery(hql);
    consulta.setString("codigo", codigo);
    consulta.setString("cpf", cpf);
    Cupom cupom = (Cupom) consulta.uniqueResult();
    session.getTransaction().commit();
    session.close();
    return cupom;
}

From source file:br.edu.ifes.sr.dw.persistencia.CupomDaoHibernate.java

@Override
public List<Cupom> buscarPorCliente(String email) {
    session.getTransaction().begin();/*from www  . ja va  2  s.co m*/
    String hql = "select c from Cupom c inner join c.cliente cli where cli.email = :email and c.resgatado = :resgatado";
    Query consulta = session.createQuery(hql);
    consulta.setString("email", email);
    consulta.setBoolean("resgatado", false);
    List<Cupom> cupons = (List<Cupom>) consulta.list();
    session.getTransaction().commit();
    session.close();
    return cupons;
}

From source file:br.edu.ifes.sr.dw.persistencia.InstituicaoDaoHibernate.java

@Override
public Instituicao validarLogin(String email, String senha) {
    session.getTransaction().begin();/*from   w w w  .  j av  a  2  s  .c  o m*/
    String hql = "select i from Instituicao i where i.email = :email and i.senha = :senha";
    Query consulta = session.createQuery(hql);
    consulta.setString("email", email);
    consulta.setString("senha", senha);
    Instituicao instituicao = (Instituicao) consulta.uniqueResult();
    session.getTransaction().commit();
    session.close();
    return instituicao;

}

From source file:br.edu.ifes.sr.dw.persistencia.InstituicaoDaoHibernate.java

@Override
public Instituicao buscar(String email) {
    session.getTransaction().begin();//  w ww  .j  a  v a2 s.co m
    String hql = "select i from Instituicao i where i.email = :email";
    Query consulta = session.createQuery(hql);
    consulta.setString("email", email);
    Instituicao instituicao = (Instituicao) consulta.uniqueResult();
    session.getTransaction().commit();
    session.close();
    return instituicao;
}