3

static mapWith = "mongo"

I am exactly not clear what does it means. According to http://grails.github.io/grails-doc/3.0.x/ref/Domain%20Classes/mapWith.html

mapWith

Purpose

The mapWith static property adds the ability to control if a domain class is being persisted.

Examples

class Airport {
  static mapWith = "none"

}

I also went through this question Remove simpledb mapWith by meta programming in dev mode

and I got an idea that in my grails application,

static mapWith = "mongo"

might be using mongoDB plugin. But still I am not clear. I also went through these stackoverflow links :

  1. get mapWith static domain field value from GrailsDomainClass grails

  2. Is it possible in grails to disable persistence of a domain class dynamically with inheritance

  3. Migration from MongoDB to PostgreSQL Groovy Application

Community
  • 1
  • 1

2 Answers2

2

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:

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

Also see this link

Grails Data Mapping Mongo Manual!

0

I agree with @Mananpreet Singh's answer, but for the static mapWith = "mongo" specifically to be clear is that it means if you want to persist a particular domain class with Mongo not Hibernate, you must use it.

http://gorm.grails.org/latest/mongodb/manual/#withHibernate

Montaro
  • 9,240
  • 6
  • 29
  • 30