Grails
  1. Grails
  2. GRAILS-7945

Named Query results should be of type PagedResultList in order to support Pagination

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.3.7
    • Fix Version/s: 2.0-M2
    • Component/s: Persistence
    • Labels:
    • Environment:
      Grails 1.3.7, Java 1.6

      Description

      Even though Named Queries use standard Criteria syntax, the result is an ArrayList instead of a PagedResultList. This makes dealing with pagination difficult.

        Issue Links

          Activity

          Hide
          Igor Aguiar added a comment -

          Hi John,
          Are you aware of the count method? You can use it to get the same totalCount value of PagedResultList

          // get up to 10 recent publications, skip the first 5… 
          def recentPubs = Publication.recentPublications.list(max: 10, offset: 5)
          // get the number of recent publications… 
          def totalCount = Publication.recentPublications.count()
          
          Show
          Igor Aguiar added a comment - Hi John, Are you aware of the count method? You can use it to get the same totalCount value of PagedResultList // get up to 10 recent publications, skip the first 5… def recentPubs = Publication.recentPublications.list(max: 10, offset: 5) // get the number of recent publications… def totalCount = Publication.recentPublications.count()
          Hide
          John Underwood added a comment -

          Hi Igor,

          Thanks for the suggestion. That is what I am already doing as a work-around. But it appears to make two calls to the database. I was hoping to avoid that.

          Show
          John Underwood added a comment - Hi Igor, Thanks for the suggestion. That is what I am already doing as a work-around. But it appears to make two calls to the database. I was hoping to avoid that.
          Hide
          Jeff Scott Brown added a comment -

          Igor,

          I have the fix worked up. Tests are running now.

          I don't think you are going to save a call to the database. I think you will save some code in your application. I think that Hibernate still has to send the separate "select count" call to the db to retrieve the totalCount but with PagedResultList but your code is a little cleaner without the second call and whatever complexity (performance) is involved in your named query criteria only has to be encountered once.

          Show
          Jeff Scott Brown added a comment - Igor, I have the fix worked up. Tests are running now. I don't think you are going to save a call to the database. I think you will save some code in your application. I think that Hibernate still has to send the separate "select count " call to the db to retrieve the totalCount but with PagedResultList but your code is a little cleaner without the second call and whatever complexity (performance) is involved in your named query criteria only has to be encountered once.
          Hide
          John Underwood added a comment -

          I'm looking through the source code of HibernateCriteriaBuilder.invokeMethod() and it looks like there are already two separate calls to the database being made. So, I guess I'll stop worrying about that issue. Thanks.

          Show
          John Underwood added a comment - I'm looking through the source code of HibernateCriteriaBuilder.invokeMethod() and it looks like there are already two separate calls to the database being made. So, I guess I'll stop worrying about that issue. Thanks.
          Hide
          Jeff Scott Brown added a comment -

          A query like this now returns a PagedResultList:

          Publication.recentPublications.list(max: 10, offset: 5)
          
          Show
          Jeff Scott Brown added a comment - A query like this now returns a PagedResultList: Publication.recentPublications.list(max: 10, offset: 5)
          Hide
          Lari Hotari added a comment -

          Should GRAILS-2672 be fixed too?

          Show
          Lari Hotari added a comment - Should GRAILS-2672 be fixed too?

            People

            • Assignee:
              Jeff Scott Brown
              Reporter:
              John Underwood
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development