Grails
  1. Grails
  2. GRAILS-8963

Named query with additional criteria does not return PagedResultList

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.0.4, 2.1.3, 2.2
    • Fix Version/s: None
    • Component/s: Persistence
    • Labels:
      None
    • Environment:
      Win7, JDK 1.6 u25, Grails 2.0.1

      Description

      I have defined a named query in a domain class:

      class Person {
          String name
          String gender
          static namedQueries = {
              malePersons {
                  eq('gender', 'male')
              }
          }
      }
      

      The following criteria queries work fine - they both return a PagedResultList:

      def personsA = Person.malePersons.list(max: 10, offset: 0)
      def personsB = Person.createCriteria().list(max: 10, offset: 0) {
          ilike('name', '%bob%')
      }
      

      But the following query does not work as expected - the result is an ArrayList and not a PagedResultList as expected:

      def personsC = Person.malePersons.list(max: 10, offset: 0) {
          ilike('name', '%bob%')
      }
      

        Issue Links

          Activity

          Hide
          Tudor Malene added a comment -

          Here is a small test case with the underlying cause of this bug:

          
              // this is the cause of  GRAILS-8963
              void testCallToMethodWithObjectArrayFirstParameter() {
                  def test8963 = new Test8963()
          
                  //behaves like this because CallSite creates an array with the map and the closure
                  test8963.list(max: 10, offset: 0) { 5 }
                  assertNull test8963.closure
                  assertEquals 2, test8963.params.size()
          
                  //fails because the closure is null ( it's in the array)
                  shouldFail(MissingMethodException) {
                      test8963.list1(max: 10, offset: 0) { 5 }
                  }
          
                  //this works
                  test8963.list([[max: 10, offset: 0]] as Object[]) { 5 }
                  assertNotNull test8963.closure
                  assertEquals 1, test8963.params.size()
              }
          
              class Test8963 {
                  def params
                  def closure
          
                  def list(Object[] params, Closure closure = null) {
                      this.params = params
                      this.closure = closure
                  }
          
                  def list1(Object[] params, Closure closure) {
                      this.params = params
                      this.closure = closure
                  }
              }
          
          
          Show
          Tudor Malene added a comment - Here is a small test case with the underlying cause of this bug: // this is the cause of GRAILS-8963 void testCallToMethodWithObjectArrayFirstParameter() { def test8963 = new Test8963() //behaves like this because CallSite creates an array with the map and the closure test8963.list(max: 10, offset: 0) { 5 } assertNull test8963.closure assertEquals 2, test8963.params.size() //fails because the closure is null ( it's in the array) shouldFail(MissingMethodException) { test8963.list1(max: 10, offset: 0) { 5 } } // this works test8963.list([[max: 10, offset: 0]] as Object []) { 5 } assertNotNull test8963.closure assertEquals 1, test8963.params.size() } class Test8963 { def params def closure def list( Object [] params, Closure closure = null ) { this .params = params this .closure = closure } def list1( Object [] params, Closure closure) { this .params = params this .closure = closure } }

            People

            • Assignee:
              Jeff Scott Brown
              Reporter:
              Jonathan Stott
            • Votes:
              6 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:

                Development