更改NHibernate的的session.save命令超时 [英] Changing NHibernate Session.Save command timeout

查看:924
本文介绍了更改NHibernate的的session.save命令超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有需要比默认的长30秒的夫妇长期运行的后端流程。

We have a couple of long running back-end processes that take longer than the default 30 seconds.

我们的NHibernate的版本为2.0.1.4000和Spring.NET是1.2.0.20313。 NHibernate的是通过Spring.NET这样配置:

Our NHibernate version is 2.0.1.4000 and Spring.NET is 1.2.0.20313. NHibernate is configured through Spring.NET this way:

<object id="SessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate20">
    <property name="DbProvider" ref="DbProvider"/> 
    <property name="MappingAssemblies">
        <list>
            <value>SomeKindOfAnItem</value>
        </list> 
    </property>
    <property name="HibernateProperties">
        <dictionary>
            <entry key="expiration" value="120"/>
            <entry key="adonet.batch_size" value="10"/>
            <entry key="cache.provider_class" value="NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache"/>
            <entry key="cache.use_query_cache" value="true"/>
            <entry key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/>
            <entry key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
            <entry key="dialect" value="NHibernate.Dialect.MsSql2005Dialect"/>
            <entry key="current_session_context_class" value="Spring.Data.NHibernate.SpringSessionContext, Spring.Data.NHibernate20"/>
            <entry key="show_sql" value="false"/>
        </dictionary>
    </property>
</object>

要解决这个问题,我想NHibernate的command_timeout设置为60在Web.config。 这是从Web.config中:

To get around this, I am trying to set the NHibernate command_timeout to 60 in the Web.config. This is from Web.config:

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

不幸的是,这并不工作,命令超时30秒后。

Unfortunately this does not work, the command times out after 30 seconds.

我建立了一个控制台应用程序调用就像web应用程序做它的DAO。我在它的配置文件完全相同的NHibernate的配置设置。的IDbCommand超时60秒,不是30后,使用设置成功地从配置文件。

I built a console app that calls the DAO just like the web app does it. I have the exact same NHibernate configuration setting in its configuration file. The IDbCommand times out after 60 seconds and not 30, using the setting successfully from the config file.

我试着调试应用程序,并检查的CommandTimeout被设置在DAO组件从网站叫。这是

I tried debugging the app and check if the commandTimeout was set when the DAO assembly is called from the web site. It was.

这是从Visual Studio手表:

This is from Visual Studio watch:

((NHibernate.Driver.DriverBase)(((NHibernate.Connection.DriverConnectionProvider)   ((NH​​ibernate.Impl.SessionFactoryImpl)session.SessionFactory)    .ConnectionProvider).Driver))的CommandTimeout:60

((NHibernate.Driver.DriverBase)(((NHibernate.Connection.DriverConnectionProvider) ((NHibernate.Impl.SessionFactoryImpl)session.SessionFactory) .ConnectionProvider).Driver)).commandTimeout: 60

这次会议是这样创建的:

The session is created like this:

ISession session = SessionFactoryUtils.GetSession(HibernateTemplate.SessionFactory, true);

我的问题是:如果命令超时场是从我的web.config成功设置为60,为什么它超时30秒后?任何想法我可以尝试?

My question is: if the command timeout field was successfully set to 60 from my Web.config, why does it time out after 30 seconds? Any ideas I could try?

推荐答案

您可以设置超时时间为hibernate.connection.connection_string财产的一部分。我没有使用Spring.Net所以我不知道它是如何建立的nhibinate会话工厂。如果你可以添加连接超时= 120到连接字符串。这将增加时间从默认为30秒超时为120秒。 下面的线将走在web配置

You could set the timeout as part of the hibernate.connection.connection_string property. I haven't used Spring.Net so I am not sure how it sets up the nhibinate session factory. if you are able to add "Connect Timeout=120" to the connection string. This should increase the time from the default 30 second timeout to 120 seconds. The following line would go in the web config

<property name="connection.connection_string">Server=localhost;initial catalog=nhibernate;User Id=;Password=; Connect Timeout=120;</property>

修改
事实证明,实际上有两个超时。感谢adomokos指出了这一点。一个用于连接的实际开口,另一个被执行的quieries

EDIT
It turns out that there are actually two timeouts. Thanks to adomokos for pointing that out. One for the actual opening of the connection and another for the quieries that are executed.

在一个用于连接显示在上方,但要使用的ICriteria接口设置超时与NHibernate的查询。

The one for the connection is displayed above, however to set the timeout for a query with nhibernate you use the ICriteria interface.

ICriteria crit = session.CreateCriteria(typeof(Foo)); 
crit.SetTimeout(120); 
List<Foo> fooList = crit.List();

的超时值以秒为单位。

The timeout value is in seconds.

希望帮助

这篇关于更改NHibernate的的session.save命令超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆