开发者

Hibernate Query selection

In a database consider that I have a table with 4000 rows. I am using JTable to lis开发者_运维百科t them in front end. During page load, I need to display only First - 20 rows. I have NEXT and PREVIOUS button in top, so that if I click NEXT button, next 20 rows must be fetched from database and loaded in table.

In short, on button click, I need to fetch a set of values (for example say 20 rows) dynamically from database. I am using Hibernate.

Can anyone suggest me a link or the procedure to do this. Any examples will be clear...

Thanks.


You could use ScrollableResults. Take into account that it might be unsupported by some DB drivers.

Or you could use setFirstResult and maxResults, for example:

Criteria criteria=session.createCriteria(Item.class);
criteria.addOrder(Order.asc("name"));
criteria.setFirstResult(100);
criteria.setMaxResults(50);
List pageResults=criteria.list();

You may also find the answers to this question useful: Using Hibernate's ScrollableResults to slowly read 90 million records

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜