Is there a more efficient way of making pagination in Hibernate than executing select and count queries?

前端 未结 11 1353
说谎
说谎 2020-12-04 16:36

Usually pagination queries look like this. Is there a better way instead of making two almost equal methods, one of which executing \"select *...\" and the other one \"count

11条回答
  •  无人及你
    2020-12-04 17:10

    here's the way pagination is done in hibernate

    Query q = sess.createQuery("from DomesticCat cat");
    q.setFirstResult(20);
    q.setMaxResults(10);
    List cats = q.list();
    

    you can get more info from hibernate docs at : http://www.hibernate.org/hib_docs/v3/reference/en-US/html_single/#objectstate-querying-executing-pagination 10.4.1.5 and 10.4.1.6 section give you more flexbile options.

    BR,
    ~A

提交回复
热议问题