How can we compute the LAST page with JPA?

Posted by Kevin on Stack Overflow See other posts from Stack Overflow or by Kevin
Published on 2010-06-16T12:50:48Z Indexed on 2010/06/16 18:52 UTC
Read the original article Hit count: 162

Filed under:
|
|

I would like to implement pagination in my Servlet/EJB/JPA-Hibernate project, but I can't figure out how only one page from the query and know the number of pages I must display

I use

setFirstResult(int first) ;
setMaxResults(int max) ;

and that's working alright, but how can I know how many pages I will have in total?

(Hibernate is my JPA provider, but I would prefer using only JPA if possible)

UPDATE: COUNT() seems to be the better/easiest solution; but what can be the cost of SELECT COUNT(*) FROM ... in comparison with executeQuery("SELECT * FROM ...).getListResult().size() ?

© Stack Overflow or respective owner

Related posts about java

Related posts about hibernate