更改 NHibernate Session.Save 命令超时

发布于 2024-08-23 01:15:15 字数 2466 浏览 3 评论 0原文

我们有几个长时间运行的后端进程,其运行时间超过默认的 30 秒。

我们的NHibernate版本是2.0.1.4000,Spring.NET是1.2.0.20313。 NHibernate 通过 Spring.NET 进行配置:

<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>

为了解决这个问题,我尝试在 Web.config 中将 NHibernate command_timeout 设置为 60。 这是来自 Web.config:

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

不幸的是,这不起作用,命令在 30 秒后超时。

我构建了一个控制台应用程序,它可以像 Web 应用程序一样调用 DAO。我的配置文件中有完全相同的 NHibernate 配置设置。成功使用配置文件中的设置后,IDbCommand 在 60 秒而不是 30 秒后超时。

我尝试调试应用程序并检查从网站调用 DAO 程序集时是否设置了 commandTimeout。是的。

这是来自 Visual Studio 的观看:

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

会话是这样创建的:

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

我的问题是:如果命令超时字段从我的 Web.config 成功设置为 60,为什么会在 30 秒后超时?我可以尝试什么想法吗?

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

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>

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>

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

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.

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

This is from Visual Studio watch:

((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);

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘你却要生生世世 2024-08-30 01:15:15

您可以将超时设置为 hibernate.connection.connection_string 属性的一部分。我没有使用过 Spring.Net,所以我不确定它是如何设置 NHibernate 会话工厂的。如果您能够将“Connect Timeout=120”添加到连接字符串中。这会将时间从默认的 30 秒超时增加到 120 秒。

web.config 中将包含以下行:

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

编辑

事实证明,实际上有两个超时。感谢 adomokos 指出这一点。一个用于实际打开连接,另一个用于执行的查询。

上面显示了连接的超时,但是要设置 NHibernate 查询的超时,您可以使用 ICriteria 接口。

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

超时值以秒为单位。

希望有帮助

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 NHibernate 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>

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 queries that are executed.

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.

Hope that helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文