Chapter 3. Persistence

The persistence strategy in Grails is called Grails object relational mapping, or GORM. In earlier versions of Grails, this was a wrapper around Hibernate’s ORM implementation, but has been abstracted to allow access to other data sources, including NoSQL datastores like MongoDB, Redis, and Neo4j. GORM for Hibernate has been retrofitted to follow the new GORM API, which provides a consistent developer experience regardless of the underlying storage implementation. See the grails-data-mapping project on GitHub for more detailed information.

But it is not merely a least-common-denominator approach where only the features that are common to all datastores are supported. Instead, there is a core set of functionality that all implementations must provide (mapping from domain classes to datastore storage, supporting dynamic finders and Criteria queries, and so on) but each provider also supports access to the underlying implementation to access noncore features directly.

This means that, for data that fits the relational model well, you can use Hibernate to manage persistence in a relational database; but, for less structured data or to support more dynamic schemas, you can use a NoSQL datastore. The Grails NoSQL plug-ins coexist well with Hibernate, so you are free to store all of your data in a relational database, all in one or more NoSQL datastores, or use a mix.

See the extensive GORM documentation in the Grails reference for more information.

Data Mapping

The convention ...

Get Programming Grails now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.