(Quick Reference)

3.1.3 配置GORM - Reference Documentation

Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith

Version: null

3.1.3 配置GORM

Grails provides the following GORM configuration options:
  • grails.gorm.failOnError - If set to true, causes the save() method on domain classes to throw a grails.validation.ValidationException if validation fails during a save. This option may also be assigned a list of Strings representing package names. If the value is a list of Strings then the failOnError behavior will only be applied to domain classes in those packages (including sub-packages). See the save method docs for more information.

For example, to enable failOnError for all domain classes:

grails.gorm.failOnError=true

and to enable failOnError for domain classes by package:

grails.gorm.failOnError = ['com.companyname.somepackage',
                           'com.companyname.someotherpackage']
  • grails.gorm.autoFlush = If set to true, causes the merge, save and delete methods to flush the session, replacing the need to explicitly flush using save(flush: true).

Grails提供了如下的GORM配置选项:

  • grails.gorm.failOnError - 如果此选项值为 true 并且在保存的时候 校验 失败,那么此领域类的 save() 方法将抛出一个 grails.validation.ValidationException 异常。此选项的值还可以是代表包名的字符串列表。如果是字符串列表的话,那么failOnError仅仅作用于属于这些包名(包括子包名)的领域类。更多详细信息请参考 save 方法

例如要使所有的领域类都能够failOnError,配置如下:

grails.gorm.failOnError=true

要使特定包名的领域类能够failOnError,代码如下:

grails.gorm.failOnError = ['com.companyname.somepackage',
                           'com.companyname.someotherpackage']
  • grails.gorm.autoFlush = 如果此选项值为 true,那么将导致 mergesavedelete 方法不需要明确地指定flush参数(比如 save(flush: true) )而清除会话的行为。