我可以将NHibernate的AdoNetTransactionFactory与分布式事务一起使用吗? [英] Can I use NHibernate's AdoNetTransactionFactory with distributed transactions?

查看:102
本文介绍了我可以将NHibernate的AdoNetTransactionFactory与分布式事务一起使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个与NHibernate和WCF服务中的分布式事务有关的奇怪问题.请参阅使用NHibernate和分布式交易以获取更多详细信息.

似乎可以解决我问题的一件事是使用NHibernate的AdoNetTransactionFactory,而不是AdoNetWithDistributedTransactionsFactory.

我相信AdoNetWithDistributedTransactionsFactory与使NHibernate的第二级缓存机制正常工作有关,但是我们没有使用它.将AdoNetTransactionFactory与分布式事务一起使用还存在哪些(如果有)其他问题?

感谢您的时间!

解决方案

AdoNetTransactionFactory分布式系统事务一起使用将导致NHibernate忽略这些事务,从而产生以下后果:

  • ConnectionReleaseMode.AfterTransaction将不被接受.相反,NHibernate将在每条语句后释放连接,因此将从池中重新获取下一条连接.根据您的数据提供者,这可能会触发将事务升级为分布式事务.
  • FlushMode.Commit将不被接受.相反,将需要显式冲洗. (Auto刷新之前仍可能会发生查询.)
  • 需要与当前系统事务隔离的作品仍将包含在其中. (除非连接字符串Enlist属性为false.)这些工作可能包括id生成器查询,例如检索表hilo生成器的下一个高值.如果事务得到回滚,则NHibernate可能会使用有冲突的ID.
  • NHibernate会话将无法正确跟踪它对实体持有的锁.考虑到交易之外的自身,它将认为它没有任何锁定.因此,它可能会尝试(以示例方式请求用户代码)以低于事务已在数据库中对其持有的锁的锁定级别来重新锁定它们.不知道会导致什么结果. (充其量是被忽略的,最糟糕的是……)
  • 一旦您开始修改数据,二级缓存将被禁用.在这种情况下,NHibernate会对无效"的缓存条目进行排序,并仅在完成事务更新后才重新启用它们.但是由于它不会知道交易...
  • 某些扩展程序(可能是Envers)可能依赖NHibernate事务事件,并且将无法按预期进行更多的工作.

I am dealing with a strange issue related to NHibernate and distributed transactions in a WCF service. See Deadlocks causing 'Server failed to resume the transaction' with NHibernate and distributed transactions for more details.

One thing that seems to solve my problem is using NHibernate's AdoNetTransactionFactory, instead of AdoNetWithDistributedTransactionsFactory.

I believe that the AdoNetWithDistributedTransactionsFactory is involved with making NHibernate's second-level caching mechanism work right, but we're not using that. What (if any) other problems exist with using AdoNetTransactionFactory with distributed transactions?

Thanks for your time!

解决方案

Using AdoNetTransactionFactory with distributed system transactions will cause those transaction to be ignored by NHibernate, which has the following consequences:

  • ConnectionReleaseMode.AfterTransaction will not be honored. Instead, NHibernate will release the connection after each statement, and so will re-acquire a connection from the pool for the next one. Depending on your data provider, this may trigger escalation of the transaction to distributed.
  • FlushMode.Commit will not be honored. Explicit flushes will be required instead. (Auto flushes before queries may still occur.)
  • Works needing to be isolated from current system transaction will still be included inside it. (Unless the connection string Enlist property is false.) Such works may include id generators queries such as retrieving the next high value for a table hilo generator. If the transaction gets roll-backed, NHibernate may then use conflicting ids.
  • The NHibernate session will not be able to correctly track locks it holds on entities. Considering itself outside of a transaction, it will consider it has no lock on them. So it may try (on user code request by example) to re-lock them with lower lock level than the one the transaction already holds on them in database. Not sure what outcome could result of that. (At best, ignored, at worst...)
  • Second level cache will be disabled as soon as you start modifying data. NHibernate sort of "invalidate" cache entries in such situation, and re-enable them only on transaction completion, updated. But since it will not be aware of transactions...
  • Some extensions (maybe Envers) may rely on NHibernate transaction events, and will no more work as expected.

这篇关于我可以将NHibernate的AdoNetTransactionFactory与分布式事务一起使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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