save() method of domain class accepts two parameters failOnError and flush (both of these parameters are optional).

  • failOnError
    when it is set to true then save() method will throw ValidationException when validation fails during save.
  • flush
    when it is set to true then save() method flush the session immediately and save data in the database.

we can use them like:

To ensure that user’s data is saving in the database or not then we have to pass failOnError: true on each and every domain instance 🙁 . Grails provide us the facility to configure failOnError in Config file and we do not need to pass failOnError: true with any domain instance 🙂 :

We can also assign a list of packages with these configuration and failOnError is only applicable to domain classes in those packages and their sub-packages:

same way we can configure flush: true alse, like:

And the best part of using these configurations instead of pass failOnError and flush parameters with every domain instance is that when ever we don’t want to use failOnError and flush then simply mark them false:

Hope this helps 🙂