hibernate3分页查询执行几次就不执行了 在每次执行的时候,都重新构造一次Criteria对象 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 action: Criteria criteria = positionManager.createCriteria(SysPosition.class); if ((this.getPositionName() != null) && (this.getPositionName().length() > 0)) { criteria.add(Expression.like("positionName","%"+this.getPositionName()+"%")); } Page page = positionManager.pagedQuery(criteria, param.getCurPage(), param.getPageSize()); this.getRequest().put("positionList", page.getResult());HibernateGenericDao public Page pagedQuery(Criteria criteria, int pageNo, int pageSize) { Assert.notNull(criteria); Assert.isTrue(pageNo >= 1, "pageNo should start from 1"); CriteriaImpl impl = (CriteriaImpl) criteria; Projection projection = impl.getProjection(); List<CriteriaImpl.OrderEntry> orderEntries; try { orderEntries = (List) BeanUtils.forceGetProperty(impl, "orderEntries"); BeanUtils.forceSetProperty(impl, "orderEntries", new ArrayList()); } catch (Exception e) { throw new InternalError(" Runtime Exception impossibility throw "); } int totalCount = (Integer) criteria.setProjection(Projections.rowCount()).uniqueResult(); criteria.setProjection(projection); if (projection == null) { criteria.setResultTransformer(CriteriaSpecification.ROOT_ENTITY); } try { BeanUtils.forceSetProperty(impl, "orderEntries", orderEntries); } catch (Exception e) { throw new InternalError(" Runtime Exception impossibility throw "); } if (totalCount < 1) return new Page(); int startIndex = Page.getStartOfPage(pageNo, pageSize); List list = criteria.setFirstResult(startIndex).setMaxResults(pageSize).list(); criteria.setProjection(null); return new Page(startIndex, totalCount, pageSize, list); } 改用DetachedCriteria吧这有个不错的例子http://www.javaeye.com/topic/14657 无语,反编译出来的class有错误 与tomcat服务器建立socket连接 高手求解:jQuery的Ajax方法getJSON中不能访问js中的变量! 关于Java的时间比较问题 log4j 不能按天记录日志 一个关于hibernate分页的逻辑问题 关于hibernate动态表名如何实现的问题 关于大小写的问题 springmvc和mybatis结合 可以直接把用mybatis写的接口注入到service层???? hibernate更改字段not null属性不生效 webservice怎么发布jsp文件啊 hibernate配置c3p0数据源疑问!!!!
Criteria criteria =
positionManager.createCriteria(SysPosition.class);
if ((this.getPositionName() != null)
&& (this.getPositionName().length() > 0)) {
criteria.add(Expression.like("positionName","%"+this.getPositionName()+"%"));
}
Page page = positionManager.pagedQuery(criteria, param.getCurPage(), param.getPageSize());
this.getRequest().put("positionList", page.getResult());
HibernateGenericDao
public Page pagedQuery(Criteria criteria, int pageNo, int pageSize) {
Assert.notNull(criteria);
Assert.isTrue(pageNo >= 1, "pageNo should start from 1");
CriteriaImpl impl = (CriteriaImpl) criteria;
Projection projection = impl.getProjection();
List<CriteriaImpl.OrderEntry> orderEntries;
try {
orderEntries = (List) BeanUtils.forceGetProperty(impl, "orderEntries");
BeanUtils.forceSetProperty(impl, "orderEntries", new ArrayList());
} catch (Exception e) {
throw new InternalError(" Runtime Exception impossibility throw ");
}
int totalCount = (Integer) criteria.setProjection(Projections.rowCount()).uniqueResult();
criteria.setProjection(projection);
if (projection == null) {
criteria.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);
} try {
BeanUtils.forceSetProperty(impl, "orderEntries", orderEntries);
} catch (Exception e) {
throw new InternalError(" Runtime Exception impossibility throw ");
}
if (totalCount < 1)
return new Page(); int startIndex = Page.getStartOfPage(pageNo, pageSize);
List list = criteria.setFirstResult(startIndex).setMaxResults(pageSize).list();
criteria.setProjection(null);
return new Page(startIndex, totalCount, pageSize, list);
}
这有个不错的例子
http://www.javaeye.com/topic/14657