Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] total rowCount with JPA

Thank you for the answer,

I now do this:

query.setFirstResult(0);
query.setMaxResults(java.lang.Integer.MAX_VALUE);
int count = query.getResultList().size();
So basically executing the query twice. Not really what I want.

Leon

Mohsen Saboorian wrote:
Hi,
AFAIK there is no such a way available with JPA 1. You should do a
either "SELECT COUNT(o) FROM Object o", or
Query.getResultList().size().

Mohsen.

On Fri, May 9, 2008 at 11:28 AM, Leon Derks <leon.derks@xxxxxxxxxx> wrote:
Hello

I know how to implement pagination, using JPA.

But I also would like to know how I can get the total number of results.

For example Hibernate uses a projection for this(see below), but how can I
do this using JPA?

criteria.setFirstResult(0);
criteria.setMaxResults(java.lang.Integer.MAX_VALUE);
criteria.setProjection(Projections.rowCount());
int rowCount = (Integer) criteria.list().get(0);

Leon


_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users





Back to the top