本文整理匯總了Java中org.hibernate.Query.setResultTransformer方法的典型用法代碼示例。如果您正苦於以下問題:Java Query.setResultTransformer方法的具體用法?Java Query.setResultTransformer怎麽用?Java Query.setResultTransformer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.hibernate.Query
的用法示例。
在下文中一共展示了Query.setResultTransformer方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: pageByHql
import org.hibernate.Query; //導入方法依賴的package包/類
@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;
}
示例2: getSingleByHql
import org.hibernate.Query; //導入方法依賴的package包/類
/**
* 獲取單個實體,根據查詢語句及參數獲取。
* 查詢列名的別名跟實體必須完全一致(如 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);
}
示例3: listByHql
import org.hibernate.Query; //導入方法依賴的package包/類
/**
* 獲取實體列表,根據查詢語句及參數獲取。
* 查詢列名的別名跟實體必須完全一致(如 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();
}
示例4: distinct
import org.hibernate.Query; //導入方法依賴的package包/類
@Override
public Query distinct(Query query) {
query.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
return query;
}
示例5: distinct
import org.hibernate.Query; //導入方法依賴的package包/類
/**
* distinct.
*
* @param query
* Query
* @return Query
*/
public static Query distinct(Query query) {
query.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
return query;
}