Using GORM in a Groovy application

GORM is a data access toolkit originally created as part of Grails framework. It supports multiple database types. The following table summarizes the modules needed to use GORM and links to documentation.

Table 2. GORM Modules
DependencyDescription

io.micronaut.groovy:micronaut-hibernate-gorm

Configures GORM for Hibernate for Groovy applications. See the Hibernate Support docs

io.micronaut.groovy:micronaut-mongo-gorm

Configures GORM for MongoDB for Groovy applications. See the Mongo Support docs.

io.micronaut.groovy:micronaut-neo4j-gorm

Configures GORM for Neo4j for Groovy applications. See the Neo4j Support docs.

Once you have configured a GORM implementation per the instructions linked in the table above you can use all features of GORM.

GORM Data Services can also participate in dependency injection and life cycle methods:

GORM Data Service VehicleService.groovy

  1. @Service(Vehicle)
  2. abstract class VehicleService {
  3. @PostConstruct
  4. void init() {
  5. // do something on initialization
  6. }
  7. abstract Vehicle findVehicle(@NotBlank String name)
  8. abstract Vehicle saveVehicle(@NotBlank String name)
  9. }

You can also define the service as an interface instead of an abstract class if you want GORM to do all of the work and you don’t want to add your own behaviors.