I am back with a new blog post titled “Controlling Domain Persistence using mapWith property”.In Grails if we want to make certain fields non-persistent we can use the transient keyword like this:

class DomainClass {
static transients = ['field1', 'field2']
Integer field1
Integer field2
Integer persistentField1
Integer persistentField2 
}

It is also possible to make a whole domain class non-persistent by using mapwith keyword.

class NonPersistentDomain {
.........
....................
.......................
static mapWith = 'none';
}

One can argue that its better to use a command object instead of a domain but it has its own advantages:

  1. It can be accessed using GrailsDomainClass.
  2. It participates while generating UI through scaffolding.

That was all!

Thanks