NHibernate Pitfalls: Batching and Native Id Generators
This is part of a series of posts about NHibernate Pitfalls. See the entire collection here.
You may be aware of batching in NHibernate. In a nutshell, it allows, if properly configured, NHibernate to issue multiple INSERT statements in a single command sent to the database, instead of sending one command for each insertion.
It happens that you cannot use batching with native (SQL Server and MySQL’s IDENTITY and Oracle and PostgreSQL’s SEQUENCEs) id generators. Why? Because these id generators don’t know the new id to be inserted beforehand and so have to issue a SELECT in order to find it out, after each each new row is inserted.
In order to use this performance enhancement, you’ll have to turn to other id generation strategy.