Deleting a lot of records part II

For the first part see this post. In my model I have one object with 85 child objects. All references are set that when the father is deleted all the childs will also be deleted. The problem is that deleting the father results in a java heap space error. I first tried to delete all the childs seperately through batches (see my first post about deleting a lot of records). I presumed that after this I could delete the father. Problem is that I now run out of garbage collection: java.lang.OutOfMemoryError: GC overhead limit exceeded. I tried already to delete this single father entity in Java (with batch size 1). But deleting this one object (with the 85 now empty children) still throws the garbage collector error. How can I solve this?
2 answers

Your options:

  • Use separate database transactions for each set of parents objects. Even with batch size 1, if you don't use separate transactions you can still have memory errors. Try to log after each batch remove. Does it fail before the fist logging? Or does it fail after a while? In the last case separate transactions will do it (see my answer here).
  • Increase your heap space. Try other JVM parameters, see this whitepaper on tuning Edit: New link.
  • Delete the childs in own batches instead of the cascading delete behavior of the framework. I can image that the delete behavior is not batch optimized (anyone?)

Thanks for all the comments. I now use the removeBatch action with the useDeleteBehavior set to false. I then do a cleanup action om the child entity to delete any leftovers without a reference.

And here is the correct link for the Java tuning white paper