package example
import grails.gorm.services.Service
@Service(Book)
abstract class BookService {
TestService testRepo
abstract Book save(String title, String author)
void doSomething() {
assert testRepo != null
}
}
1 Introduction
Version: 2023.3.0
Table of Contents
1 Introduction
GORM is a data access framework with multiple backend implementations that allows you to rapidly write data access code with little effort for your favourite database.
There are currently several implementations of GORM. This documentation covers the original implementation of GORM which is based on the Hibernate ORM. Below you can find links to the other implementations:
As mentioned, GORM for Hibernate is the original implementation of GORM and has evolved dramatically over the years from a few meta-programming functions into a complete data access framework with multiple implementations for different datastores relational and NoSQL.
1.1 Upgrade Notes
Dependency Upgrades
GORM 2023.3 supports Apache Groovy 4 and Java 17, Hibernate 5.6.x and Spring 6.1.x.
Each of these underlying components may have changes that require altering your application. These changes are beyond the scope of this documentation.
Default Autowire By Type inside GORM Data Services
A GORM Service (or a bean) inside GORM DataService will default to autowire by-type, For example:
./app/services/example/BookService.groovy
Please note that with autowire by-type as the default, when multiple beans for same type are found the application with throw Exception. Use the Spring @Qualifier
annotation for Fine-tuning Annotation Based Autowiring with Qualifiers.
JPA-annotated Entites are not supported
Support for using JPA-annotated entites written in Groovy has been added since GORM 6.1, but this feature has been removed since GORM 2023.0.
We want to keep GORM focusing on Groovy DSL, this allow developers to use JPA entities written in Java in the app/domain
, so we can use Spring Data JPA or Micronaut Data JPA.
Initial support for Groovy 5
Groovy 5.0 is the next major version, it’s currently in beta, but you can try it in the Grace applications.
Auto-Configure Hibernate Plugin
GORM 2023.1.0 introduced HibernateGormAutoConfiguration
as a Spring Boot’s Auto-configuration, and the Hibernate plugin has also provides Configuration Metadata.
Most importantly, you can now easily use GORM for Hibernate in your Spring Boot application.
dependencies {
implementation 'org.apache.groovy:groovy'
implementation 'org.graceframework.plugins:hibernate:2023.3.0'
runtimeOnly 'com.h2database:h2'
}
Support @GrailsComponentScan
GORM 2023.1.0 use @GrailsComponentScan
to customize GORM @Entity
scanning locations, just like Spring’s @ComponentScan
does.
./app/init/example/Application.groovy
package example
import grails.boot.annotation.GrailsComponentScan
@GrailsComponentScan(basePackages=['com.appone', 'com.apptwo'])
class Application {
}