具有多个约束的gorm实体

时间:2011-05-10 08:29:38

标签: grails gorm grails-domain-class

class Book {

String name
String author       
 static constraints = { name(nullable:true) 
}
}

以上似乎有效,但是当我为多个字段设置约束时,服务器无法启动

class Book {

String name
String author       
 static constraints = { name(nullable:true) author(nullabe:false)
}
}

使用上面的代码......我得到以下异常

  

引起:groovy.lang.MissingMethodException:没有方法签名:org.codehaus.groovy.grails.validation.ConstrainedPrope   rty.call()适用于参数类型:(org.codehaus.groovy.grails.validation.ConstrainedProperty)值:[org.codehau   s.groovy.grails.validation.ConstrainedProperty@3343e5 [class com.nthdimenzion.domain.Book,author,class java.lang.String,{nulla   ble=org.codehaus.groovy.grails.validation.NullableConstraint@1aea6e2 [FALSE]}]]   可能的解决方案:wait(),any(),wait(long),each(groovy.lang.Closure),any(groovy.lang.Closure),isUrl()           在com.nthdimenzion.domain.Book $ _ clinit _closure1.doCall(Book.groovy:16)           在com.nthdimenzion.domain.Book $ _ clinit _closure1.doCall(Book.groovy)           ......还有23个

有什么想法吗?

1 个答案:

答案 0 :(得分:4)

因为你把它放在同一条线上......

 static constraints = { 
    name(nullable:true) 
    author(nullabe:false)
 }

编辑:

您可以将条目与;分开,然后如果您想要的话,可以将其全部放在一行上。 (但我认为我们大多数人不使用oneliners ......)