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

License:Open Source License

/**
 * ?count(*)?hql??//from  w  w  w  . j av a2  s  . c om
 * 
 * @param hql the hql
 * 
 * @return the toatal by hql
 */
public int countHql(String hql, Object value) {
    //
    Query query = getSession().createQuery(hql);
    //??
    query.setParameter(0, value);
    Long result = (Long) query.uniqueResult();
    if (result != null) {
        return result.intValue();
    }
    return 0;
    //return total;
}

From source file:baking.dao.BaseDao.java

License:Open Source License

/**
 * ?count(*)?hql??/*from w  w w .  j  av  a  2 s  . c  o m*/
 * 
 * @param hql the hql
 * 
 * @return the toatal by hql
 */
public int countHql(String hql, Object[] values) {
    //
    Query query = getSession().createQuery(hql);
    //??
    if (values != null && values.length > 0) {
        for (int i = 0; i < values.length; i++)
            query.setParameter(i, values[i]);
    }
    Long result = (Long) query.uniqueResult();
    if (result != null) {
        return result.intValue();
    }
    return 0;
}

From source file:baking.dao.BaseDao.java

License:Open Source License

/**
 * ?count(*)where in?hql??/*from  www. ja v a 2 s  . c  o  m*/
 * 
 * @param hql the hql
 * 
 * @return the toatal by hql
 */
public int countHql(String hql, String name, List vals) {
    //
    Query query = getSession().createQuery(hql);
    //??
    query.setParameterList(name, vals);
    Long result = (Long) query.uniqueResult();
    if (result != null) {
        return result.intValue();
    }
    return 0;
    //return total;
}

From source file:bitirme.dao.AdminDao.java

public Admin girisKontrol(Admin admin) {
    session = HibernateUtil.getSessionFactory().openSession();
    String sorgu = "Select a from Admin a WHERE k_adi = :k_adi AND k_parola= :k_parola";
    try {//from ww  w .  j a  va  2s  . c  o m
        Query q = session.createQuery(sorgu);
        q.setParameter("k_adi", admin.getKAdi());
        q.setParameter("k_parola", admin.getKParola());

        Admin u = (Admin) q.uniqueResult();

        session.close();
        return u;
    } catch (Exception e) {
        session.close();
        return null;
    }
}

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

@Override
public Integer getIdPorCodigo(String codigo) {
    Query query = getSession().createQuery("SELECT id from Area a WHERE a.codigo = :codigo");
    query.setParameter("codigo", codigo);
    return (Integer) query.uniqueResult();
}

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

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

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

@Override
public String getCodigo(Integer id) {
    Query query = getSession().createQuery("SELECT codigo from Area a WHERE a.id = :id");
    query.setParameter("id", id);
    return (String) query.uniqueResult();
}

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

@Override
public Area recuperarPorCodigo(String codigo) {
    Query query = getSession().createQuery("from Area a WHERE a.codigo = :codigo");
    query.setParameter("codigo", codigo);
    return (Area) query.uniqueResult();
}

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

@Override
public Integer getIdPorCodigo(String codigo) {
    Query query = getSession().createQuery("SELECT id from Calidad c WHERE c.codigo = :codigo");
    query.setParameter("codigo", codigo);
    return (Integer) query.uniqueResult();
}

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

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