我尝试向我的应用程序添加批量插入,但 Batcher 仍然是 NonBatchingBatcher,BatchSize 为 1。
这是使用 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 身份生成,但不是为数据库上的所有实例。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>