Chapter 3. Modeling the domain

 

This chapter covers

  • What GORM is and how it works
  • How domain classes are saved and updated
  • Techniques for validating and constraining fields
  • Domain class relationships (1:1, 1:m, m:n)

In this chapter, we explore Grails’s support for the data model portion of your applications (getting stuff into the database and querying to get it back), and if you’re worried we’ll dig deep into complex outer joins, you’ll be pleasantly surprised how straightforward Grails makes data access. We won’t write a line of SQL, and you won’t find any Hibernate XML mappings here either. We’ll take full advantage of the convention over configuration paradigm we introduced in chapter 1, which means less time configuring and more time getting work done.

We’ll spend most of our time exploring how Grails persists domain model classes to your data store of choice (be it a relational database or a shiny new NoSQL store) using GORM, mentioned briefly in chapter 2. You’ll also learn how GORM models various relationships (one to many, many to many, and so on.)

But we’re practitioners, not theorists, so we’ll discuss these topics while building the heart of the sample application you’ll use throughout this book: Hubbub. You won’t spend much time on the UI in this chapter, but the concepts we’ll cover are fundamental for building the rock-solid data models that back our applications.

Without further ado, let’s look at your sample application.

3.1. Introducing the Hubbub sample application

3.2. Your first domain class object

3.3. Validation: stopping garbage in and out

3.4. Defining the data model—1:1, 1:m, m:n

3.5. Summary and best practices

sitemap