Chapter 3. Modeling the domain

 

This chapter covers

  • What GORM is and how it works
  • Defining domain model classes
  • 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’ll explore Grails’ support for the data model portion of your applications, and if you’re worried we’ll be digging deep into outer joins, you’ll be pleasantly surprised. We won’t be writing a line of SQL, and you won’t find any Hibernate XML mappings here either. We’ll be taking full advantage of the Convention over Configuration paradigm, which means less time configuring and more time getting work done.

We’ll be spending most of our time exploring the basics of how Grails persists domain model classes using GORM—the Grails object relational mapping implementation. 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 we’ll use throughout this book: Hubbub. We won’t be spending much time on the user interface (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 our sample application.

3.1. Hubbub: starting our example 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