是不是NHibernate的"每个请求&QUOT一次会议;模式有点危险长期Web请求?一次会议、危险、模式、NHibernate

由网友(污瘾善糜)分享简介:在我的,我们正在使用NHibernate的会议包装,全部部署在同一请求结束当前Web请求开了会议,并提交所有相关事务工作的公司(我们正在处理一个多数据库环境中,我们创建一个会话的每个数据库)。In the company I work for, we're using a NHibernate session wra...

在我的,我们正在使用NHibernate的会议包装,全部部署在同一请求结束当前Web请求开了会议,并提交所有相关事务工作的公司(我们正在处理一个多数据库环境中,我们创建一个会话的每个数据库)。

In the company I work for, we're using a NHibernate session wrapper that disposes all the sessions opened in the current web request at the end of the same request, and commits all the associated transactions (we're working in a multi-database environment, and we create a session for every database).

另外,我们正在使用的会话包装,会话和交易耦合,我们不能提交事务没有处理的会话。

Also, in the session wrapper we're using, the session and the transactions are coupled, and we can't commit a transaction without disposing its session.

的问题是,有时,一个事务保持打开的所有请求生命和数据库表保持锁定为太时间

The problem is that, sometimes, a transaction stays open for all the request life, and database tables stays locked for much too time.

...是我们失去了一些东西?

... are we missing something?

推荐答案

每个请求的会话只有一个办法做到的会话生命周期管理。这恰好是推荐的策略Web应用程序,但NHibernate的是真的无动于衷,你如何管理你的会话有效期。

Session per request is only one way to do session lifecycle management. It happens to be the recommended strategy for web apps, but NHibernate is really indifferent to how you manage your session lifetime.

您当然可以使用具有或长或短的生活比一个请求的会议。如果你有使用的情况下,将更好地工作,以这种方式,通过各种手段,去了。

You can certainly use sessions that have shorter or longer lives than a single request. If you have use cases that would work better in that way, by all means, go for it.

不要让你的会话的包装把不必要的限制你的适应NHibernate的,以应用程序的需求的能力。

Don't let your session wrapper put unnecessary constraints on your ability to adapt NHibernate to the needs of your application.

阅读全文

相关推荐

最新文章