Takeshi8059
Takeshi8059

Reputation: 33

Why nhibernate doesn't allow to make batch insert during stateless session with identity identifier?

I'm trying to optimize database calls from my code using batching in NHibernate. I'm working on a process that sends more than 1 thousand queries separately (I want to optimize this).

The NHibernate version is 4.

The core problem that I'm using Identity type for generation ID.

I tried to use both sessions and stateless sessions.

I would like to use batch insert even for identity column mapping. In case I work with a stateless session, which does not collect cache on my insertions, I don't understand why I do not allow me to batch my queries.

Is that is possible?

P.S. I don't want to use SQLBulkCopy. My options are limited to Nhiberante features.

Upvotes: 1

Views: 893

Answers (1)

Amit Joshi
Amit Joshi

Reputation: 16389

Is that is possible?

Batching is not supported by NHibernate if key column is identity. This is because, NHibernate have to execute the INSERT statement and get back the generated (by RDBMS) identity. This will not be possible in case of batching.

Note that NHibernate disables insert batching at the ADO level transparently if you use an identity identifier generator.
Source

I don't want to use SQLBulkCopy. My options are limited to Nhiberante features.

SQL Bulk Copy is commonly used alternative for this scenario bypassing NHibernate; consider it.

Upvotes: 2

Related Questions