How can we compute the LAST page with JPA?
- by Kevin
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() ?