Hibernate分页

1.使用Criteria

Criteria crit = sess.createCriteria(Cat.class);
crit.setFirstResults(100);
crit.setMaxResults(50);
//当有连表查询时,删除结果中重复的项目
crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
List cats = crit.list();

2.使用NativeSQL

对于MySQL

SQLQuery query = sess.createSQLQuery("SELECT ID, NAME, BIRTHDATE, DOG_ID FROM
CATS LIMIT 100,50").addEntity(Cat.class);
List cats = query.list();

相关推荐