Cannot bulk insert using NHibernate

I tried adding bulk insertion to my application, but Batcher is still a NonBatchingBatcher with a BatchSize of size 1.

It uses C # 3, NH3RC1 and MySql 5.1

I added this to my SessionFactory

<property name="adonet.batch_size">100</property>

And my code is very similar to this

var session = SessionManager.GetStatelessSession(type);
var tx = session.BeginTransaction();
session.Insert(instance);

I use HILO generation generation for the instances in question, but not for all instances in the database. SessionFactory.OpenStatelessSession does not accept a type, so it cannot really know that it can perform batch processing of this type or ...?

After some digging in NHibernate, I found something in the SettingsFactory.CreateBatcherFactory file that might give more info

// It defaults to the NonBatchingBatcher
System.Type tBatcher = typeof (NonBatchingBatcherFactory);

// Environment.BatchStrategy == "adonet.factory_class", but I haven't
// defined this in my config file
string batcherClass = PropertiesHelper.GetString(Environment.BatchStrategy, properties, null);
if (string.IsNullOrEmpty(batcherClass))
{
    if (batchSize > 0)
    {
        // MySqlDriver doesn't implement IEmbeddedBatcherFactoryProvider,
        // so it still uses NonBatchingFactory
        IEmbeddedBatcherFactoryProvider ebfp = connectionProvider.Driver as IEmbeddedBatcherFactoryProvider;

Can my configuration be wrong?

  <hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
    <session-factory name="my application name">
      <property name="adonet.batch_size">100</property>
      <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
      <property name="connection.connection_string">my connection string
      </property>
      <property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>
      <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
      <!-- To avoid "The column 'Reserved Word' does not belong to the table : ReservedWords" -->
      <property name="hbm2ddl.keywords">none</property>
    </session-factory>
  </hibernate-configuration>
+3
source
3

IIRC, Oracle SqlServer.

NH, , IBatcher/IBatcherFactory .

Sidenote: NH 3.0 GA.

+2

, - , NuGet, MySQL NHibernate. , NHibernate, , MySQL.Data, .

+3

, ...

Another reason batch processing doesn't work is to use a stateless session (as in your case). A non-save session does not support batch processing. From the documentation :

The insert (), update (), and delete () operations defined by the StatelessSession interface are considered to be a direct database of row-level operations that lead to the immediate execution of the SQL INSERT, UPDATE, or DELETE query, respectively. Thus, they have very different semantics of the Save (), SaveOrUpdate () and Delete () operations defined by the ISession interface.

0
source

Source: https://habr.com/ru/post/1786181/


All Articles