2

I'm trying to save a large grails domain object structure, where the number of domain classes is a handful, but the number of objects around a hundred. The objects are linked using classic grails hasMany.

The basic idea is to wipe the database first and then populate it with a configuration DSL using a custom groovy builder. The builder returns a complete object graph/tree, which I then want to save.

I have tried various ways to save it, such as save just the root node, traverse the whole tree saving every node etc. However, Hibernate bails out at various places complaining about a flushed session.

Has anyone done something similar and can give some pointers/advice how to proceed?

Would it be better to integrate the save() operations as part of the build process, e.g. nodeCompleted(parent, node)?

Has Hibernate a maximum of the number of outstanding SQL operations, that has become exceeded?

4

2 回答 2

0

尝试创建 rootNode、addToChildNodes 并使用 rootNode.save(flush:true) 来保存对象树。

于 2013-01-23T21:01:14.933 回答
0

如果它确实是一个完整的对象树(使用 belongsTo 关键字),那么根节点的保存应该级联到所有其他对象。但是,手动保存每个项目也应该可以正常工作,只要您在除最后一次保存之外的任何内容上都没有说 flush:true 。

当我处理大量对象时,出于完全不同的原因,我发现像这样进行手动会话处理很有帮助:

MyDomainClass.withSession { context ->
  //my stuff here
  //save
}

查看错误消息本身和您的域类结构也可能很有用。

于 2012-03-02T17:32:02.300 回答