Grails – Setting failOnError globally

One of the small annoyances with Grails that I’ve found is that the application doesn’t fail when a call to the “save” method fails. One of the ways to fix this is to pass the “failOnError” parameter to the save method, set to true:

def book = new Book(title: “The Shining”).save(failOnError: true)

However, this gets annoying, having to pass the parameter every time that you call the “save” method. A solution is to declare it as the default setting and forget about it.

This can be done in Config.groovy, by adding the following line:

grails.gorm.failOnError=true

You can also add this configuration to specific packages, in case that you didn’t want the configuration to apply to all of the packages used in your application:

grails.gorm.failOnError = [‘com.companyname.somepackage’,’com.companyname.someotherpackage’]

From: http://grails.org/doc/latest/guide/conf.html#configGORM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.