扩展hibernate的方言。使hibernate支持row_number
hibernate对于sqlserver2005真分页 ).append(limit);
28
????????????
return
sql.toString();
29
????????
}
30
????
}
31
????
//使offset 参数生效
32
????
public
boolean
supportsLimitOffset(){
33
????????
return
true
;
34
????
}
最后再 hibernate.cfg.xml 配置 dialect
<property name="dialect">
????? com.java1995.dialect.Java1995SQLServerDialect
</property>
测试结果如下:
Query q = session.createQuery("from Cat as c order by c.id asc"); //注意要加 order by 才能用到 ROW_NUMBER分页
q.setFirstResult(10000);
q.setMaxResults(20);
List l = q.list();
生成的sql 语句为
select * from (select?? ....,ROW_NUMBER() OVER(order by cat0_.id asc) as _page_row_num_hb from
cat as cat0_) temp where _page_row_num_hb BETWEEN? 10001 and 10020