Java Reference
In-Depth Information
Finally, transactions are managed using Spring's declarative transaction capabilities, using
the @Transactional annotation. All Grails service methods are transactional by de-
fault, but their behavior can be customized using the annotation.
Settingupallthisinfrastructure—managing thesessionsandtransactions, mappingdomain
classestotables,establishing relationships, handlingoptimistic locking,generatingdynam-
ic finders and criteria queries, and scoping the Hibernate session to each request—requires
a lot of work when putting Spring and Hibernate together manually. Grails does all of this
for you, and much more besides.
The Spring framework is one of the most common open source projects in all of Java, and
Hibernate is still the most common ORM tool. Any project considering using them togeth-
er owes it to itself to consider using Grails.
Lessons learned (Groovy and GORM)
1 . Groovy simplifies all database access by using POGOs instead of POJOs, using
closures for result set processing, and making building and testing easier.
2 . The GORM API makes configuring Hibernate-based applications easy. When
combined with Spring (as in Grails), transactions and the Hibernate session become
simple, too.
3 . It's not so easy to use GORM outside of Grails, which is tightly tied to Spring.
Trying to do so is rare enough in the industry that the process wasn't covered in this
chapter.
Recent versions of Grails can also map to non-relational databases, but you can also use
regular Groovy to do that, as the next section shows.
8.5. Groovy and NoSQL databases
One of the most interesting trends in software development in the past few years [ 15 ] has
been the growth of alternative, non-relational databases. The generic term NoSQL (which
Search WWH ::




Custom Search