简体   繁体   English

Grails域类失败

[英]Grails domain class failing

The class is below: 该类如下:

package tsg

class Country {

    String code
    String codeShort
    String name
    String en
    String nl
    String de
    String fr
    String it
    String es

    static mapping = {
        id name: "code", generator: "assigned"
        version 'revision_number'
    }

    static constraints = {
        code maxSize: 4
        codeShort nullable: true, maxSize: 2
        name nullable: true, maxSize: 100
        en nullable: true, maxSize: 50
        nl nullable: true, maxSize: 50
        de nullable: true, maxSize: 50
        fr nullable: true, maxSize: 50
        it nullable: true, maxSize: 50
        es nullable: true, maxSize: 50
    }
}

And when I run 'grails run-app' I get: 当我运行“ grails run-app”时,我得到:

| Error 2014-12-12 18:43:55,468 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener  - Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException: Cannot invoke method call() on null object
Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException: Cannot invoke method call() on null object
    Line | Method
->>  262 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException: Cannot invoke method call() on null object
->>  262 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException: Cannot invoke method call() on null object
->>  262 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread
Caused by NullPointerException: Cannot invoke method call() on null object
->>   25 | doCall    in tsg.Country$__clinit__closure2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    262 | run       in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . in java.lang.Thread
| Error Forked Grails VM exited with error
  1. The funny thing is that, if instead the language name - en, fr, de, etc. I put something longer - lng_en, lng_fr, etc. it works. 有趣的是,如果改为使用语言名称-en,fr,de等。我放了更长的名称-lng_en,lng_fr等。它可以工作。

  2. If I take out the constrains for the languages fields, again, it works. 如果我排除了语言字段的限制,它仍然可以工作。

  3. If I leave only the en constrain, it works.(the rest - nl, de, fr, it, es - are commented). 如果我只留下en约束,则它起作用。(其余的-nl,de,fr,it,es-被注释)。 I uncomment nl, run 'grails run-app' and it works. 我取消nl的注释,运行'grails run-app'并且它起作用。 I uncomment de, run 'grails run-app' again and it works. 我取消注释,再次运行“ grails run-app”即可。 But if I uncomment 2 fields at a time I get the same error. 但是,如果我一次取消注释2个字段,则会收到相同的错误。 What could be the cause? 可能是什么原因? Any ideas how to make it work (besides renaming the fields)? 有什么想法使它起作用(除了重命名字段)?

Your problem is with the variable it . 您的问题在于变量it Inside of the closure it refers to the implicit optional argument to the constraints closure. 在闭包内部, it指向constraints闭包的隐式可选参数。 You can get around that by naming the argument... 您可以通过命名参数来解决此问题。

class Country {

    String code
    String codeShort
    String name
    String en
    String nl
    String de
    String fr
    String it
    String es

    static mapping = {
        id name: "code", generator: "assigned"
        version 'revision_number'
    }

    static constraints = { arg ->
        code maxSize: 4
        codeShort nullable: true, maxSize: 2
        name nullable: true, maxSize: 100
        en nullable: true, maxSize: 50
        nl nullable: true, maxSize: 50
        de nullable: true, maxSize: 50
        fr nullable: true, maxSize: 50
        it nullable: true, maxSize: 50
        es nullable: true, maxSize: 50
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM