Java Reference
In-Depth Information
A Gradle build file is contained in the topic source code. It looks like most of the build files
shown in earlier chapters, but it's considerably shorter and easier to read than the corres-
ponding Maven build.
8.4.2. Grails Object-Relational Mapping (GORM)
The Grails framework consists of a set of Groovy DSLs on top of Spring and Hibernate.
Because the combination of Spring and Hibernate is a very common architecture in the
Java world, Grails is a natural evolution that simplifies the coding and integration issues.
Grails is discussed in more detail in
chapter 10
on web applications, but the Hibernate in-
tegration part is relevant here. Grails combines Groovy domain-specific languages (DSLs)
to make configuring the domain classes easy.
Domain Classes
In Grails the term
domain
is like
entity
in JPA. Domain classes map to database tables.
Consider a small but nontrivial domain model based on the same
Product
class used
earlier in this chapter. The next listing shows the
Product
class, now in Groovy.
Listing 8.10. The
Product
class, this time as a POGO in a Grails application
class Product {
String name
double price
String toString() { name }
static constraints = {
name blank:false
price min:0.0d
}
}
In Grails each domain class implicitly has a primary key called
id
of some integer type,
which isn't shown here but exists nevertheless. The
constraints
block here is part of