Grails - Object Relational Mapping (GORM)



Description

The Grails is a full stack open source framework which uses Hibernate framework as well as implements its own Object Relational Mapping (ORM) layer for groovy known as GORM.

GORM is the persistence component of Grails for handling relational databases. The Object Relational Mapping is implemented in Grails called Domain Class.

In this chapter we will see how GORM implements its Object model in the domain class. You can create a domain class by using the following command−

grails create-domain-class Employee

Creating a domain class

D:\Projects\helloworld>grails
grails> create-domain-class Employee
| Rendered domain class to grails-app/domain/helloworld/Employee.groovy
| Rendered domain class to src/test/groovy/helloworld/EmployeeSpec.groovy
grails>

The above command will create a file Employee.groovy which looks like−

package helloworld

class Employee {

    static constraints = {
    }
}

Let's modify the generated file by adding the properties−

package helloworld

class Employee {
    String Firstname
    Integer age
    static constraints = {
    }
}

Once done, use the below command in shell or console to load an interactive GUI to run Groovy commands−

grails
Advertisements