Java Code Examples for org.springframework.orm.hibernate3.HibernateTemplate#setMaxResults()

The following examples show how to use org.springframework.orm.hibernate3.HibernateTemplate#setMaxResults() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseDao.java    From JgFramework with Apache License 2.0 6 votes vote down vote up
@Override
public List<IBaseModel> findAll(int start, int limit) {
    log.debug("finding all Object instances");
    try {
        HibernateTemplate ht = getHibernateTemplate();
        int PRE_MAX_RESULT = ht.getMaxResults();
        int PRE_LIMIT = ht.getFetchSize();
        ht.setMaxResults(limit);
        ht.setFetchSize(start);
        String queryString = "from " + this.modelName;
        List<IBaseModel> list = ht.find(queryString);
        ht.setMaxResults(PRE_MAX_RESULT);
        ht.setFetchSize(PRE_LIMIT);
        return list;
    } catch (RuntimeException re) {
        log.error("find all failed", re);
        throw re;
    }
}
 
Example 2
Source File: BaseDAO.java    From QiQuYingServer with Apache License 2.0 2 votes vote down vote up
/**
 * @Title: find
 * @Description: 执行HQL查询,无参数
 * @param @param queryString
 * @param @return
 * @param @throws DataAccessException
 * @return List<T>
 */
public <T> List<T> findFirst(String queryString, Object... values) throws DataAccessException {
	HibernateTemplate hibernateTemplate = getHibernateTemplate();
	hibernateTemplate.setMaxResults(1);
	return (List<T>) hibernateTemplate.find(queryString, values);
}