Get result count from criteria query [message #724377] |
Mon, 12 September 2011 08:37 |
dreske Missing name Messages: 17 Registered: August 2010 |
Junior Member |
|
|
Hello,
I build an criteria query, to get some entities from the database.
For pagination reasons, I set firstResult and maxResults to get only a subset of the total result.
Is there a way to get the whole entity count of this query, without manually building a second count query?
This is because I want to build a method in my service base class, that returns the paginated result, by giving it only the query object that returns the results.
I imagine something like this:
public<T> PaginatedResult<T> executeQuery(CriteriaQuery<T> query, Paginator paginator) {
....
}
The Paginator object includes firstResult and maxResults and the PaginatedResult contains the List<T> and a totalResults fields.
So the concrete service implementation has to build the query, to get its data, and the above method executes this and gets the data AND the total results, this query would return without pagination.
My problem is, that I have to build a second "count query", but in this method I've no informations about the where-clauses, etc attached to the query.
thanks
Dirk
|
|
|
Re: Get result count from criteria query [message #724593 is a reply to message #724377] |
Mon, 12 September 2011 15:57 |
|
There is no standard method in JPA for this.
You could pass an inner class instead of the CriteriaQuery that knows how to build the query, then add a count to it.
With EclipseLink you could create a Query from the CriteriaQuery, cast it to a JpaQuery and get the DatabaseQuery from it. You could then build a ReportQuery with the DatabaseQuerys selectionCriteria and add a count.
James : Wiki : Book : Blog : Twitter
|
|
|
|
Powered by
FUDForum. Page generated in 0.02976 seconds