java - How can we compute the LAST page with JPA? -


I want to start pointing the page in my service / EJB / JPA-Hibernate project, but I can not understand this How do I get a page from the query and I should know what is the number of pages

I use

  setFirstResult (int first); SetMaxResults (max max);  

And it's working fine, but how do I know how many pages will I have in the total?

(Hibernate is my JApA provider, but JPA only if possible)

UPDATE: COUNT () looks better / easier solution; But what is the cost of SELECT COUNT (*) FROM ... compared to executeQuery ("SELECT * FROM ...). GetListResult (). Size () ?

AFAIK, you need to either count (1) or (2) complete hit list and pages The number of times is the count of total count / page size.

There are several methods of counting, like using a COUNT (*)

 < Code> query query = em.createQuery ("use employee SELECT COUNT (emp.empName)");  

or any other on Using projection

  Standards.Setprocessing (projection.orcount ()); int rowCount = (integer) criteria.list (). Get (0);  

Note that I have never used this one, I read it somewhere.

I have documented some other details about endorsement in this reply: / P>

Hope this help


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -