Grails 2.3.6. Scaffolding index page throws ArrayIndexOutOfBoundsException

I have a grails application that does not work at runtime in a cryptic way (to quote me anyway) with an ArrayIndexOutOfBoundsException when I visit scaffolded / imca2 / imcaReferral / index.

* now edited to end the solution *

There are about a dozen domain classes. I have not yet begun to worry about the user interface, so all controllers are dynamically tinted.

All other controllers work fine.

This controller :

package com.ubergen
class ImcaReferralController {
    def scaffold = ImcaReferral
}

For this domain:

package com.ubergen
class ImcaReferral {
    private def todayDate = new Date()
    String          advocacyReferenceNum        = ""
[snip a lot of code]
    String toString() {
        "${this.advocacyReferenceNum}: ${this.client?this.client:'-'}${this.referralIssue?', '+this.referralIssue:''}"
    }
}

(I do not want to publish the domain class here as my huge).

Creates this stack :

|Server running. Browse to http://localhost:8080/imca2
| Error 2014-03-12 18:48:24,935 [http-bio-8080-exec-3] ERROR errors.GrailsExceptionResolver  - ArrayIndexOutOfBoundsException occurred when processing request: [GET] /imca2/imcaReferral/index
0. Stacktrace follows:
Message: 0
    Line | Method
->>   55 | <init>     in grails.orm.PagedResultList
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     15 | $tt__index in com.ubergen.ImcaReferralController
|    191 | doFilter . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter   in grails.plugin.cache.web.filter.AbstractFilter
|   1146 | runWorker  in java.util.concurrent.ThreadPoolExecutor
|    615 | run        in java.util.concurrent.ThreadPoolExecutor$Worker
^    701 | run . . .  in java.lang.Thread

Cleaning and (re) compiling make no difference.

, .

, eclipse/STS. .

run-app --noreloading ( ). run-war .

run-app --verbose :

| Error 2014-03-12 19:58:37,745 [http-bio-8080-exec-1] ERROR errors.GrailsExceptionResolver  - ArrayIndexOutOfBoundsException occurred when processing request: [GET] /imca2/imcaReferral/index
0. Stacktrace follows:
java.lang.ArrayIndexOutOfBoundsException: 0
    at org.hibernate.criterion.Order.toSqlString(Order.java:73)
    at org.hibernate.loader.criteria.CriteriaQueryTranslator.getOrderBy(CriteriaQueryTranslator.java:394)
    [snip]
    at grails.orm.PagedResultList.<init>(PagedResultList.java:55)
    [snip]
    at com.ubergen.ImcaReferral.list(ImcaReferral.groovy)
    [snip]
    at com.ubergen.ImcaReferralController.$tt__index(script1394654146228610896735.groovy:15)
    [snip]

, (), , , stacktrace.

?

ubuntu 10.04
eclipse / SpringToolSuite 3.4.0
grails 2.3.6
groovy 2.1.9 (for both project and workspace)

13/03/2014

(. ) , ImcaReferral.list().

grails :

package com.ubergen
ImcaReferral.withTransaction { status -> 
    ImcaReferral.list()
 } 

java.lang.ArrayIndexOutOfBoundsException: 0
at org.hibernate.criterion.Order.toSqlString(Order.java:73)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getOrderBy(CriteriaQueryTranslator.ja a:394)
[snip]
at com.ubergen.ImcaReferral.list(ImcaReferral.groovy)

BINGO!, , , .

:

package com.ubergen
class ImcaReferral {
    ...
    static hasMany = [challenges:Challenge]
    static mapping = {
         ...
         sort dateReceived:'asc' 
      // sort challenges:'challengeRoute'   // *** ERROR ***
    }
}

( ) .

:

package com.ubergen
class ImcaReferral {
    ...
    static hasMany = [challenges:Challenge]
    static mapping = {
        ...
        sort dateReceived:'asc' 
        challenges sort: 'challengeRoute', order: 'asc' // *** CORRECT ***
    }
}

. .

  • stacktrace, . , .

  • .

    grails-reloading

  • !

+4
1

Static Scaffolding , . , , .

+1

Source: https://habr.com/ru/post/1531429/


All Articles