Active Record/Nhibernate TransactionScopes 问题

发布于 2024-09-11 18:03:51 字数 691 浏览 2 评论 0原文

这个问题纯粹与AR相关。

假设我的 web/wcf 应用程序中有 2 个层 - DataLayer 和 BusinessLayer。 DataLayer 包含用于映射的几乎原子操作(查找、获取、保存、特殊查找、交叉查找等:))。有很多 HQL 或标准。该层没有使用 SessionScopes。我的一些映射包含惰性集合。

现在,BL 层的方法包含与 DL 调用混合的业务逻辑 - 这是正常的。对于内部具有只读操作的每个公共方法,我指定了 SessionScope(FlushAction.Never) 。对于所有具有保存或更新操作的方法,我使用 TransactionScope(),其中包含 try catch,在方法末尾使用直接 VoteCommit,并在 catch 子句中使用 VoteRollback。我已将 ReadCommited 设置为隔离级别。

对于基本情况,这是有效的。当我编写使用其他方法且内部有自己的事务的方法时,我开始遇到真正的问题 - 我说的是锁。例如,我有递归事务的方法。 似乎某些“读取”方法(具有自己的 SessionScope(FlushAction.Never))由于其他事务而被阻止。

我无法真正找出到底出了什么问题,但我开始认为我有一些重大的设计问题。

城堡网站上的帮助对我来说没什么用,还有 AR 源的测试 - 它们对我来说太基础了。

任何人都可以真正解释我应该如何使用 TransactionScopes 或者我的错误是什么?

This question is purely AR related.

Let's say I have 2 layers in my web/wcf application - DataLayer and BusinessLayer.
DataLayer contains almost atomic operations that work on mappings (find, get, save, special find, cross find , etc. :) ). There is a lot of HQL or Criterias. There's no SessionScopes used in this layer. Some of my mappings contain lazy collections.

Now, the BL layer has methods that contain business logic included mixed with DL calls - that's normal. For each public method that have readonly operations inside I have SessionScope(FlushAction.Never) specified. For all those methods that have some Save or Update operations, I'm using TransactionScope(), with try catch inside, with direct VoteCommit at the end of the method and VoteRollback inside catch clause. I have ReadCommitted set as isolationLevel.

For basic situations this works. I started to have real problems when I wrote methods that uses other methods with their own transactions inside - I'm talking about locks. For example I have method with transaction that is recursive.
It seems that some 'read' methods (that have their own SessionScope(FlushAction.Never)) are blocked because of other transactions.

I can't really track down what exactly is wrong, but I'm starting to think that I have some major design problem.

Help on castle site doesn't do much for me, also tests in AR sources - they are simply too basic for me.

Can anyone really explain how should I use the TransactionScopes or what's my mistake?

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

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

发布评论

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

评论(1

混浊又暗下来 2024-09-18 18:03:51

我建议使用 Castle.Service.Transaction,它允许您以声明方式进行交易而不是明确地。这通常通过自动事务管理工具使用,但是它需要温莎

I recommend using Castle.Service.Transaction, it allows you to do transactions declaratively instead of explicitly. This is typically used through the Automatic Transaction Management facility, but it requires Windsor.

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