Java Code Examples for org.hibernate.Query.setResultTransformer()

The following are Jave code examples for showing how to use setResultTransformer() of the org.hibernate.Query class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: admin-shiro   File: DaoSupport.java   View Source Code Vote up 6 votes
@SuppressWarnings({"unchecked"})
public <T> Pagination<T> pageByHql(Class<T> clazz, CharSequence queryString, int pageIndex,
                                   int pageSize, Object... params) {
    Query query = getSession().createQuery(queryString.toString());

    if ((pageSize > 0) && (pageIndex > 0)) {
        query.setFirstResult((pageIndex - 1) * pageSize);
        query.setMaxResults(pageIndex * pageSize);
    }

    setParameter(query, params);
    query.setResultTransformer(Transformers.aliasToBean(clazz));

    List<T> items = query.list();
    Long rowsCount = (Long) getSingleColumnByHql(getCountStr(queryString.toString()), params);
    Pagination<T> pagination = new Pagination((long) pageIndex, (long) pageSize, rowsCount);
    pagination.setItems(items);
    return pagination;
}
 
Example 2
Project: admin-shiro   File: DaoSupport.java   View Source Code Vote up 5 votes
/**
 * 获取单个实体,根据查询语句及参数获取。
 * 查询列名的别名跟实体必须完全一致(如 select a.uid as uid ao Admin as a , AdminRole as ar where a.uid=ar.adminId and a.uid=?
 */
public <T> T getSingleByHql(Class<T> clazz, CharSequence queryString, Object... params) {
    Query query = getSession().createQuery(queryString.toString());
    setParameter(query, params);
    query.setMaxResults(1);
    query.setResultTransformer(Transformers.aliasToBean(clazz));
    List<T> list = query.list();
    if (list.isEmpty()) {
        return null;
    }
    return list.get(0);
}
 
Example 3
Project: admin-shiro   File: DaoSupport.java   View Source Code Vote up 5 votes
/**
 * 获取实体列表,根据查询语句及参数获取。
 * 查询列名的别名跟实体必须完全一致(如 select a.uid as uid ao Admin as a , AdminRole as ar where a.uid=ar.adminId and a.uid=?
 */
public <T> List<T> listByHql(Class<T> cl, CharSequence queryString, Object... params) {
    Query query = getSession().createQuery(queryString.toString());
    setParameter(query, params);
    query.setResultTransformer(Transformers.aliasToBean(cl));
    return query.list();
}
 
Example 4
Project: DWSurvey   File: SimpleHibernateDao.java   View Source Code Vote up 4 votes
@Override
public Query distinct(Query query) {
	query.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
	return query;
}
 
Example 5
Project: lemon   File: HibernateUtils.java   View Source Code Vote up 2 votes
/**
 * distinct.
 * 
 * @param query
 *            Query
 * @return Query
 */
public static Query distinct(Query query) {
    query.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

    return query;
}