アプリケーションに一括挿入を追加しようとしましたが、Batcher はまだ BatchSize が 1 の NonBatchingBatcher です。
これは、C#3、NH3RC1、MySql 5.1 を使用しています。
これをSessionFactoryに追加しました
<property name="adonet.batch_size">100</property>
そして、私のコードはこのようになります
var session = SessionManager.GetStatelessSession(type);
var tx = session.BeginTransaction();
session.Insert(instance);
問題のインスタンスには HILO ID 生成を使用していますが、データベース上のすべてのインスタンスには使用していません。SessionFactory.OpenStatelessSession は型をとらないため、この型でバッチ処理を実行できるかどうかを実際に認識できませんか、それとも...?
NHibernate を掘り下げた後、SettingsFactory.CreateBatcherFactory で追加情報を提供する可能性のあるものを見つけました。
// 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;
構成が間違っている可能性はありますか?
<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>