Example usage for org.hibernate Query setParameter

List of usage examples for org.hibernate Query setParameter

Introduction

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

Prototype

@SuppressWarnings("unchecked")
Query<R> setParameter(int position, Object val);

Source Link

Document

Bind a positional query parameter using its inferred Type.

Usage

From source file:bo.com.kibo.dal.impl.PatioHibernateDAO.java

@Override
public Integer getIdPorNombre(String nombre) {
    Query query = getSession().createQuery("SELECT id from Patio p WHERE p.nombre = :nombre");
    query.setParameter("nombre", nombre);
    return (Integer) query.uniqueResult();
}

From source file:bo.com.kibo.dal.impl.PatioHibernateDAO.java

@Override
public boolean checkId(Integer id) {
    Query query = getSession().createQuery("SELECT 1 from Patio p WHERE p.id = :id");
    query.setParameter("id", id);
    return (query.uniqueResult() != null);
}

From source file:bo.com.kibo.dal.impl.PatioHibernateDAO.java

@Override
public String getNombre(Integer id) {
    Query query = getSession().createQuery("SELECT nombre from Patio p WHERE p.id = :id");
    query.setParameter("id", id);
    return (String) query.uniqueResult();
}

From source file:bo.com.kibo.dal.impl.PatioHibernateDAO.java

@Override
public List<Patio> obtenerPatiosSegunArea(Integer idArea) {
    Query query = getSession().createQuery("from Patio p Where p.area.id = :idArea");
    query.setParameter("idArea", idArea);
    return query.list();
}

From source file:bo.com.kibo.dal.impl.PatioHibernateDAO.java

@Override
public Integer getIdPatioPorNombre(String nombre, Integer idArea) {
    Query query = getSession()
            .createQuery("SELECT id from Patio p " + "WHERE p.nombre = :nombre AND p.area.id = :idArea");
    query.setParameter("nombre", nombre);
    query.setParameter("idArea", idArea);
    return (Integer) query.uniqueResult();
}

From source file:bo.com.kibo.dal.impl.RolHibernateDAO.java

@Override
public boolean checkId(Integer id) {
    Query query = getSession().createQuery("SELECT 1 from Rol r WHERE r.id = :id");
    query.setParameter("id", id);
    return (query.uniqueResult() != null);
}

From source file:bo.com.kibo.dal.impl.RolHibernateDAO.java

@Override
public Integer getIdPorDescripcion(String descripcion) {
    Query query = getSession().createQuery("SELECT id from Rol r WHERE r.descripcion = :descripcion");
    query.setParameter("descripcion", descripcion);
    return (Integer) query.uniqueResult();
}

From source file:bo.com.kibo.dal.impl.RolHibernateDAO.java

@Override
public String getDescripcion(Integer id) {
    Query query = getSession().createQuery("SELECT descripcion from Rol r WHERE r.id = :id");
    query.setParameter("id", id);
    return (String) query.uniqueResult();
}

From source file:bo.com.kibo.dal.impl.RolPermisoHibernateDAO.java

@Override
public List<RolPermiso> getPermisos(int idRol, Integer idPadre) {
    Query query;
    if (idPadre == null) {
        query = getSession().createQuery("from RolPermiso rp where rp.rol.id =  :idRol "
                + "and rp.permiso in (from Permiso p where p.padre is null)");
    } else {/*from w  w w .  j ava  2s  .c  o  m*/
        query = getSession().createQuery("from RolPermiso rp where rp.rol.id = :idRol and "
                + "rp.permiso in (from Permiso p where p.padre.id = :idPadre)");
        query.setParameter("idPadre", idPadre);
    }
    query.setParameter("idRol", idRol);
    List<RolPermiso> resultado = query.list();
    for (RolPermiso rp : resultado) {
        rp.getPermiso().getDescripcion();
    }
    return resultado;
}

From source file:bo.com.kibo.dal.impl.TrozaHibernateDAO.java

@Override
public Integer getIdPorCodigoArea(String codigo, Integer idArea) {
    Query query = getSession()
            .createQuery("Select id From Troza t Where t.codigo = :codigo AND t.area.id = :idArea");
    query.setParameter("idArea", idArea);
    query.setParameter("codigo", codigo);
    return (Integer) query.uniqueResult();
}