[hibernate-issues] [Hibernate-JIRA] Resolved: (HHH-2143) Add support for projection to the Query API as in the Criteria API to ease automated pagination of HQL queries

Christian Bauer (JIRA) noreply at atlassian.com
Thu Oct 12 07:54:24 EDT 2006


     [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2143?page=all ]
     
Christian Bauer resolved HHH-2143:
----------------------------------

    Resolution: Won't Fix

int totalCount = myQuery.scroll().last().getRowNumber() + 1;
int totalCount = myCriteria.scroll().last().getRowNumber() + 1;

And close the cursor.

> Add support for projection to the Query API as in the Criteria API to ease automated pagination of HQL queries
> --------------------------------------------------------------------------------------------------------------
>
>          Key: HHH-2143
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2143
>      Project: Hibernate3
>         Type: Improvement

>   Components: query-hql
>     Reporter: Cédric Vidal

>
>
> Today, both the Criteria and Query APIs have setMaxResults and setFirstResult methods. Thanx to these methods, it is really easy to add pagination to an existing Criteria or Query in technical code in order to remove that consideration from user code.
> But, most of the time, it is also necessary to display the total number of records or the number of pages which either way requires to fetch the total number of records which would be returned by the query. The Criteria API introduced the setProjection(Projection) method which elegantly enables to do just that:
> // User code
> Criteria existingCriteria = session.createCriteria(Cat.class);
> // Technical Pagination code
> Integer count = (Integer)existingCriteria
>     .setProjection( Projections.rowCount() )
>     .uniqueResult();
> The problem is that the Query API lacks the setProjection method. Today, with an HQL query, one has to manually write in user code the additional count(*) specific query that returns the total number of results.
> It would be very usefull as well as time saving to be able to do the same as in the Query API:
> // User code
> Query existingQuery = session.createQuery("from Cat")
> // Technical Pagination code
> Integer count = (Integer)existingQuery
>     .setProjection( Projections.rowCount() )
>     .uniqueResult();
> Regards,
> Cédric Vidal

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira





More information about the hibernate-issues mailing list