无法使用NHibernate进行大容量插入

无法使用NHibernate进行大容量插入,nhibernate,bulkinsert,stateless-session,Nhibernate,Bulkinsert,Stateless Session,我已经尝试将批量插入添加到我的应用程序中,但批处理程序仍然是BatchSize为1的非批处理批处理程序 这是使用C#3、NH3RC1和MySql 5.1实现的 我已将此添加到我的SessionFactory中 <property name="adonet.batch_size">100</property> 我正在对有问题的实例使用HILO标识生成,但不是对数据库上的所有实例都使用HILO标识生成。SessionFactory.OpenStatelessSession不

我已经尝试将批量插入添加到我的应用程序中,但批处理程序仍然是BatchSize为1的非批处理批处理程序

这是使用C#3、NH3RC1和MySql 5.1实现的

我已将此添加到我的SessionFactory中

<property name="adonet.batch_size">100</property>
我正在对有问题的实例使用HILO标识生成,但不是对数据库上的所有实例都使用HILO标识生成。SessionFactory.OpenStatelessSession不接受类型,因此它不能真正知道它可以在此类型上执行批处理,或者

在深入研究NHibernate之后,我在setingsFactory.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>

100
NHibernate.Driver.MySqlDataDriver
我的连接字符串
NHibernate.dialogue.mysql5dialogue
NHibernate.ByteCode.Castle.proxyFactory,NHibernate.ByteCode.Castle
没有一个

IIRC,批处理目前仅支持Oracle和SqlServer

与NH的几乎任何其他方面一样,这是可扩展的,因此您可以编写自己的
IBatcher
/
IBatcherFactory
,并通过配置注入它们


旁注:NH的当前版本是3.0GA。

我知道这个问题已经有一年了,但是有一个问题将MySQL批处理功能添加到了NHibernate中。它没有直接烘焙到NHibernate中的原因是,该功能需要对MySQL.Data程序集的引用,而开发团队不需要依赖关系。

这是一个很老的问题,但……让我们完全正确

批处理不起作用的另一个原因可能是使用无状态会话(如您的情况)。无状态会话不支持批处理。发件人:

由定义的insert()、update()和delete()操作 无状态会话接口被认为是直接数据库 行级操作,可立即执行SQL 分别插入、更新或删除。因此,它们有非常不同的定义 Save()、SaveOrUpdate()和Delete()操作的语义 由ISession接口定义


当然我似乎记得以前使用Ado.Net在MySql上使用过批处理。。我也找不到太多关于这方面的信息。我想我必须深入研究一些代码,看看是否能得到至少部分支持。我知道GA已经发货了。源代码中只有3种IBatcher实现:OracleDateClient、SqlClient和非批处理,所以我认为这是不可能的。您可能会将其与所有DBs都可以使用的
batch size
属性相混淆。但是没有IBatcher,batch size就没有什么可说的了,对吗?这完全无关,但我看到有人混淆了它们。您是否将此包与NH3.2+3.3保持最新?
  <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>