NHibernate命令\u超时不适用于批处理

NHibernate命令\u超时不适用于批处理,nhibernate,timeout,batch-processing,Nhibernate,Timeout,Batch Processing,今天我遇到了一个超时问题 我有以下用于创建SessionFactory的配置: <property name="adonet.batch_size">50</property> <property name="command_timeout">600</property> 因此,我可以拥有多个具有独立配置的会话工厂(每个数据库) 但是命令\u timeout似乎只有在NHibernate不使用批处理时才有效。如果SQL命令是批处理的,那么对于

今天我遇到了一个超时问题

我有以下用于创建SessionFactory的配置:

 <property name="adonet.batch_size">50</property>
 <property name="command_timeout">600</property>
因此,我可以拥有多个具有独立配置的会话工厂(每个数据库)

但是
命令\u timeout
似乎只有在NHibernate不使用批处理时才有效。如果SQL命令是批处理的,那么对于一些大批,我会得到:

NHibernate.Exceptions.GenericADOException: could not execute batch command.
[SQL: SQL not available] --->
System.Data.SqlClient.SqlException: Timeout expired. 
The timeout period elapsed prior to completion of the operation or the server is not responding.
在谷歌搜索解决方案时,我发现一篇文章解释了为什么会发生这种情况:

问题的原因是,对于SQL批处理,NHibernate使用Cfg.Environment.CommandTimeout,而不是
命令\u timeout
,该命令在创建会话时传递给配置

我找到了一种在创建配置时实施变通方法的方法:

configuration.Configure(cfgFile)
if (configuration.Properties.ContainsKey(NHibernate.Cfg.Environment.CommandTimeout))
    NHibernate.Cfg.Environment.Properties[NHibernate.Cfg.Environment.CommandTimeout] = 
            configuration.Properties[NHibernate.Cfg.Environment.CommandTimeout];
现在,我的同事们说,超时时间似乎已经确定了

但让我困惑的是以下线索:

上面说:

属性NHibernate.Cfg.Environment.Properties将返回一个副本 全局属性,因此您无法修改它

如果NHibernate.Cfg.Environment.Properties是一个只读副本,那么为什么我的解决方案似乎工作正常?它是否稳定,或者此修复程序不可靠,在其他情况下可能会中断

我还在NHibernate JIRA中发现了一个相关问题:

如果他们说他们修复了v3.1.0中命令超时的问题,那么为什么我还必须使用NHibernate v3.3.2中的变通方法呢


有人对此有什么见解吗?

我在使用批处理时也遇到了同样的问题。Nhibernate类SqlClientBatchingBatcher使用Environment.GlobalProperties中的命令超时,该命令为只读。我在SqlClientBatchingBatcher.currentBatch命令上只找到了两种设置超时的方法

1) 在app.config文件中使用超时

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="command_timeout">120</property>
  </session-factory>
</hibernate-configuration>

120
2) 设置环境

FieldInfo field = typeof(global::NHibernate.Cfg.Environment).GetField("GlobalProperties", System.Reflection.BindingFlags.NonPublic |                                     System.Reflection.BindingFlags.Static);
Dictionary<string, string> gloablProperties = field.GetValue(null) as Dictionary<string, string>;
gloablProperties.Add("command_timeout","120");
FieldInfo field=typeof(global::NHibernate.Cfg.Environment).GetField(“GlobalProperties”,System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
Dictionary gloablProperties=field.GetValue(null)作为Dictionary;
添加(“命令超时”,“120”);

我会在这里使用
global::NHibernate.Cfg.Environment.CommandTimeout
属性而不是字符串常量
“command\u timeout”