Is there a way to change the data type of the static hasMany = [myList: Stuff]
definition in grails? I tried
List<Stuff> myList
hasMany = [myList : Stuff]
but my existing tests started throwing
Stuff._MyContainer_mylistBackref; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value
which indicates the two aren't equivalent in terms of how they're being handled. What am I d开发者_Go百科oing wrong here?
As described in section 5.2.4 of the Grails manual, this is the correct way to make the collection a List
.
I suspect the problem is that by default the constraint nullable(false)
is applied to all domain class properties and you're trying to save a null value for this property. To fix this, add a constraint that allows this property to be null (if that's what you want
List myList
static constraints = {
myList(nullable: true)
}
Alternatively, make sure that the property is not null before the object is validated/saved.
精彩评论