/gorm-standalone-example

Gorm Standalone example - Grails 2.x (Grails < 2.3)

Primary LanguageGroovyApache License 2.0Apache-2.0

Using GORM without Grails

Summary

This is a simple example demonstrating the usage of GORM outside Grails.

  • The application loads Spring Beans definitions using the Grails Spring DSL
  • Once the Spring Beans are accessible, some persons(domain objects) are persisted using a Spring Service.

Notes

  • Gradle is used as build system and the project was tested under JDK6.
  • This test application doesn’t work for Grails 2.3 and latest versions.
  • For recent versions of Grails 2.4+, please refer to the gorm-standalone-example-2_4_x project.

Configuration and Data

Here are the main resources of the project:

  • Gradle build file (build.gradle)
  • Spring bean definitions using the Grails Spring DSL (src/main/resources/SpringBeans.groovy)
  • Resource bundle for validation errors translations (src/main/resources/message.properties)
  • Log4j configuration (src/main/resources/log4j.properties)

Gotchas

  • Dependency resolution and GORM (methods missing in some Spring Framework releases expected to be found by specific GORM versions)
  • Other dependencies issues depending on the versions of Grails (grails-bootstrap), Spring Framework and GORM (grails-gorm)
  • For domain operations, either use transactional services or make sure that the Hibernate session is bound:
    • domainClass.withNewSession
    • domainClass.withTransaction

Running the application

Execute the following targets to test and run the application

On Unix/Linux platforms, run the following command:

./gradlew test run

For MS Windows please run the following command:

gradlew.bat test run

Generating IDE project files

This is for people who would rather not use Gradle.

Unix/Linux platforms

Please run the following command:

./gradlew idea eclipse

Windows

Please run the following command:

gradlew.bat idea eclipse