views:

143

answers:

1

If I configure NHibernate with a batch size of say 20, am I likely to run into problems in regular, non-batch-update related scenarios?

The majority of updates/inserts performed by my application are once-offs. But in certain cases I am doing large scale updates/inserts which would benefit from batching. Should I use a different session configuration for these, or do you think I can safely leave the batch size higher for the entire app?

The reason I ask is that it is hassle to setup a different session just for the batching scenarios (because this is a web app with per-request sessions).

+1  A: 

In the NH documentation, the only negative to batch updates that is mentioned is this:

optimistic concurrency checking may be impaired since ADO.NET 2.0 does not return the number of rows affected by each statement in the batch, only the total number of rows affected by the batch.

And I would not think that would be a problem for small batches. So I doubt that a higher batch size will negatively affect your application's normal functioning.

However, you should consider creating a new session for your batch operations anyway. A normal NHibernate session is going to be inefficient for batch updates/inserts, because the first-level cache tracks every single object. You can control this manually by doing session.Flush(); session.Clear(); regularly, but it is probably easier to use a StatelessSession instead.

Gabe Moothart