grailsgrails-ormgrails-domain-classbootstrapping

Saving a domain object in grails


I can't save the domain objects in grails on Windows 8.1 and Centos 7. Whenever I try to create an empty domain class and save it in BootStrap.groovy, I'm always getting the same error message after running the application:

Error |
2014-11-10 14:53:44,225 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener  - Error initializing the appl
ication: Method on class [com.test.Book] was used outside of a Grails application. If running in the context of a test
 using the mocking API or bootstrap Grails correctly.
Message: Method on class [com.test.Book] was used outside of a Grails application. If running in the context of a test
 using the mocking API or bootstrap Grails correctly.
    Line | Method
->>    5 | doCall                           in BootStrap$_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    327 | evaluateEnvironmentSpecificBlock in grails.util.Environment
|    320 | executeForEnvironment . . . . .  in     ''
|    296 | executeForCurrentEnvironment     in     ''
|    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

My domain class:

package com.test

class Book {
    String name
    static constraints = {
    }
}

BootStrap.groovy:

import com.test.Book
class BootStrap {

    def init = { servletContext ->
        new Book(name: "My Book").save()
    }
    def destroy = {
    }
}

I tried with both 2.4.3 and 2.4.4 versions of grails. My jdk version is 1.7.0_71 (Tried with jdk6 and jdk8, too). The interesting is, I tried the exact steps on Ubuntu and OpenSuse and I've managed to save the object without problem. So, what can be the problem?

Regards,


Solution

  • The problem is solved. It seems grails have problems with language packages of the Operating System. I was using Turkish language pack of Windows and Centos. Now I've changed it to English and the problem is solved.