Validation Grails默认的可空约束

Validation Grails默认的可空约束,validation,grails,gorm,Validation,Grails,Gorm,在我的Grails应用程序中,我有以下命令对象 @Validateable class CalendarEventCommand { @BindingFormat('FestivalType') Collection<FestivalType> types Date start Date end MapFocalPoint location boolean freeOnly = false } 在Config.groovy中,我指定

在我的Grails应用程序中,我有以下命令对象

@Validateable
class CalendarEventCommand {

    @BindingFormat('FestivalType')
    Collection<FestivalType> types
    Date start
    Date end
    MapFocalPoint location
    boolean freeOnly = false
}
Config.groovy
中,我指定了以下作为默认约束

grails.gorm.default.constraints = {

    // apply a max size of 191 chars to String columns to support utf8mb4
    // http://mathiasbynens.be/notes/mysql-utf8mb4
    '*'(maxSize: 191)

    // this shared constraint provides a way to override the default above for long text properties
    unlimitedSize(maxSize: Integer.MAX_VALUE)
}
如果为
start
end
创建了一个空值的实例,则验证将通过,但我不希望通过,因为默认的
nullable:false约束应应用于所有属性。我试图通过将第一个默认约束更改为

'*'(maxSize: 191, nullable: false)
但是当
start
和/或
end
为空时,
validate()
仍然返回
true
。如果我将这些约束添加到
CalendarEventCommand

static constraints = {
    start nullable: false
    end nullable: false
}
static constraints = {
    start nullable: false
    end nullable: false
}

然后
validate()。关于这个功能,JIRA有两个缺陷,而且似乎更关注行为

我正在经历一个只处理域类的全局约束的过程。我认为我们最终必须采用后面提到的方式

static constraints = {
    start nullable: false
    end nullable: false
}