Sunday, 14 November 2010

Grails Tip: save() fail - the silent killer!

The conventions in Grails are usually very sensible and obvious, but the lack of notification on failure to save() a domain object is counter intuitive.

The simple solution is to enable the fail on error in the Config.groovy:

grails.gorm.failOnError=true

You can apply the setting on a case by case basis as follows:

quote.save(failOnError:true)

See docs for more details

There are historical reasons why the default is set to allow silent failure of save() and there is a discussion on the newsgroup to change the default behaviour to raise an exception on failure.