Spring 具有一对多关系的Grails数据绑定-回父级的链接丢失

Spring 具有一对多关系的Grails数据绑定-回父级的链接丢失,spring,grails,data-binding,Spring,Grails,Data Binding,在Grails 2.2.2应用程序中,我有一个一对多的关系,看起来像这样: Client client = new Client() client.modelFieldInstances = ListUtils.lazyList(new ArrayList(), {new ModelFieldInstance()} as org.apache.commons.collections.Factory) client.properties = properties ... client.save()

在Grails 2.2.2应用程序中,我有一个一对多的关系,看起来像这样:

Client client = new Client()
client.modelFieldInstances = ListUtils.lazyList(new ArrayList(), {new ModelFieldInstance()} as org.apache.commons.collections.Factory)
client.properties = properties
...
client.save()
Invalid property 'modelFieldInstances[31]' of bean class [com.myapp.Client]: Illegal attempt to get property 'modelFieldInstances' threw exception; nested exception is org.springframework.beans.InvalidPropertyException: Invalid property 'modelFieldInstances[31]' of bean class [com.myapp.Client]: Cannot get element with index 31 from Set of size 0, accessed using property path 'modelFieldInstances[31]'**
家长:

class Client {
    ...
    String name
    static hasMany = [modelFieldInstances: ModelFieldInstance]
    ...
}
儿童:

class ModelFieldInstance {
    ...
    String name
    String value
    static belongsTo = [client: Client]
    ...
}
我正在尝试创建一个数据导入器,以便用户可以导入包含其客户记录的电子表格或csv。为此,我检查了grailscaffolding在标准scaffolding控制器的
save
方法中创建新的
Client
实例时使用的参数

问题是,当我尝试使用导入程序创建和保存一个新的
客户端
实例时,子
ModelFieldInstance
s被保存,而不引用父
客户端
客户端
ModelFieldInstance

在我的导入程序中,我正在执行以下数据绑定:

Client client = new Client()
client.modelFieldInstances = ListUtils.lazyList(new ArrayList(), {new ModelFieldInstance()} as org.apache.commons.collections.Factory)
client.properties = properties
...
client.save()
Invalid property 'modelFieldInstances[31]' of bean class [com.myapp.Client]: Illegal attempt to get property 'modelFieldInstances' threw exception; nested exception is org.springframework.beans.InvalidPropertyException: Invalid property 'modelFieldInstances[31]' of bean class [com.myapp.Client]: Cannot get element with index 31 from Set of size 0, accessed using property path 'modelFieldInstances[31]'**
我认为Grails脚手架控制器的工作方式与导入器的工作方式之间唯一的真正区别在于,在导入器中,我最初将
modelFieldInstances
集合设置为
LazyList
。然而,在我添加
LazyList
赋值之前,数据绑定出现了如下错误:

Client client = new Client()
client.modelFieldInstances = ListUtils.lazyList(new ArrayList(), {new ModelFieldInstance()} as org.apache.commons.collections.Factory)
client.properties = properties
...
client.save()
Invalid property 'modelFieldInstances[31]' of bean class [com.myapp.Client]: Illegal attempt to get property 'modelFieldInstances' threw exception; nested exception is org.springframework.beans.InvalidPropertyException: Invalid property 'modelFieldInstances[31]' of bean class [com.myapp.Client]: Cannot get element with index 31 from Set of size 0, accessed using property path 'modelFieldInstances[31]'**

因此,我想问题是,当我看到数据绑定在脚手架控制器中对给定的属性映射起作用时,为什么数据导入器中的数据绑定不起作用呢(
client
)中的每一个。这似乎很好,但是我仍然不确定grails数据绑定为什么不能为我做到这一点。我想知道在
GrailParameterMap
中是否有一些神奇的事情发生