What is GORM ?

GORM is Grails’ object relational mapping (ORM) implementation, which sits on top of the very popular Hibernate framework. If you are familliar with Hibernate then understanding GORM will be easy. GORM is very straightForward and easy to learn.

ORM frameworks objective is to present an API where you can just think and program in objects, and the underlying framework will handle how to interface with the relational database.
Configuration:
Grails have by default database configuration already so that you could start coding your business logic right away. By default, it uses embedded H2 database. You can change this configuration if you want in Datasource.groovy file, as shown below:
dataSource {
pooled = true
driverClassName = “com.mysql.jdbc.Driver”
dialect = “org.hibernate.dialect.MySQL5InnoDBDialect”
}

As GORM is ORM so corresponding table will be created automatically for all your domain classes. You don’t have to create the tables manually in your database or write an sql statement for this.

When tables are created you can start with CRUD part.

Lets take an example of Project class:
class Project{
String name;

}

Create operation:
Project p = new Project()
p.name = “Project_1″
p.save()

or you can do as following also:
Project p = new Project(name:”Project_1″).save()

Read operation:
Following code retrieves row of table Project with id=’12’.
Project p = Project.get(12);

Update operation:
To perform update operation you can do following :
Project p = Project.get(12)
p.name = “Project_New”
p.save()

Delete operation:
To delete a row just invoke delete() on instance to delete as shown below:
Project p = Project.get(12)
p.delete()

With GORM writing of business logic becomes very easy and convenient .


ProsperaSoft offers Grails development solutions. You can email at info@prosperasoft.com to get in touch with ProsperaSoft Grails experts and consultants.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>