1

I'm trying to find more information about how nHibernate decides how to batch multiple inserts together. Apparently it just works if you have a simple list of objects of the same type, with no children objects.

In my application, I have a one-to-many relation between three tables A, B, and C: A has many B, B has many C. I'm using a native generator for A's Id, but for B and C I'm just using composite-keys, which are assigned in the code, so that nHibernate can only do inserts. These seem to be working fine, and I can get all the objects saved properly.

The problem is that nHibernate doesn't seem to be smart enough to try to first insert all objects of type A in batch, then all B in batch, and finally all C in batch. Right now, it tries to batch only the objects of type C, if there are multiple.

Does this sound correct? Is there any way to change this behavior?

My application needs to add hundreds of objects of types A,B and C at the same time, and having to do one by one is a big performance problem.

Eduardo Scoz
  • 24,653
  • 6
  • 47
  • 62

1 Answers1

1

In case anyone ever needs any help, nHibernate indeed cannot batch insert objects in different trees. In my application, I ended up modifying the object structure to make nHibernate happy.

Eduardo Scoz
  • 24,653
  • 6
  • 47
  • 62
  • May I ask, what did you change in your object structure? – Newbie Dec 10 '11 at 02:49
  • Back in '10, I ended up creating different lists, so I could insert the objects in the correct order (first all the leafs, then those leafs parents, and so on). It seems though that the latest versions of nHibernate can properly batch insert objects in order; I just saw that on their list release notes, so I don't really know how well it works. – Eduardo Scoz Dec 10 '11 at 16:25
  • Thanks for the quick reply. I was wondering if it was possible to batch together all the inserts together A,B, and C. But it seems that it can only batch IDbCommands that are exactly the same(same SQL, same # of params). I'm using 3.2, and it is not smart enough to that yet. I will probably end-up implementing my own SqlClientBatcher. – Newbie Dec 10 '11 at 19:54