Java Reference
In-Depth Information
That's a fair amount of code and configuration, and I've only got one class and one data-
base table. Frankly, if I can't make that work, I might as well give it up. It's when you add
relationships that life gets complicated. [ 10 ]
10 On many levels; sometimes the jokes just write themselves.
Lessons learned (Hibernate and JPA)
1 . The Java Persistence API manages object-relational mapping providers that con-
vert objects to table rows and back again.
2 . Hibernate is the most common JPA provider in the industry.
3 . ORM tools provide transitive persistence, persistence contexts, SQL code genera-
tion, and more.
4 . Like all Java libraries, they're still pretty verbose.
Groovy can help this situation in a couple of ways, which will be discussed in the next sec-
tion.
8.4. The Groovy approach, part 2: Groovy and GORM
Before getting into the Grails Object-Relational Mapping (GORM) part of Grails, let me
identify a couple of places where Groovy can simplify the example application from the
previous section.
8.4.1. Groovy simplifications
The entity class Product could be written as a POGO. That wouldn't change the behavi-
or, but it would cut the size of the class by about two-thirds. That and the other Spring-re-
lated parts of the application could be converted to Groovy, which is shown in more detail
in chapter 7 on Spring.
 
Search WWH ::




Custom Search