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?

Ribomation
  • 121
  • 4

2 Answers2

0

Try to create the rootNode, addToChildNodes and use rootNode.save(flush:true) to save the tree of objects.

0

If it really is a full object tree (using the belongsTo keyword) then a save of the root node should cascade to all the other objects. However, manually saving each item should be working as well, so long as you aren't saying flush:true on any but the last save.

When I was handling large numbers of objects, for completely separate reasons, I found it helpful to do manual session handling like so:

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

It also might be useful to see the error message itself and your domain class structure.

dhore
  • 83
  • 2
  • 4