无法设置默认的 Nhibernate 隔离级别(例如通过映射)
这是我的 3 个项目中都存在的问题。
我尝试过以下操作:
<property name="connection.isolation">ReadCommitted</property>
在 hibernate.cfg.xml 中设置
使用流畅的 nhiberate:
MsSqlConfiguration.MsSql2008.IsolationLevel(IsolationLevel.ReadCommitted);
在 global.asax.cs 中设置
我一直被迫像这样设置它:
CurrentNhibernateSession.Transaction.Begin(IsolationLevel.ReadCommitted);
这有效。 (我可以使用 NHibernate Profiler 看到这一点)
问题是现在我正在使用尖锐的架构,并且 transaction.begin 在该框架内被调用,并且我在重建它时遇到了麻烦。
有没有一种方法可以在开始交易时无需显式设置即可实现此目的?
This has been a problem that has existed on 3 projects for me.
I have tried the following:
<property name="connection.isolation">ReadCommitted</property>
Set in hibernate.cfg.xml
Using fluent nhiberate:
MsSqlConfiguration.MsSql2008.IsolationLevel(IsolationLevel.ReadCommitted);
Set in global.asax.cs
I have always been forced to set it like so:
CurrentNhibernateSession.Transaction.Begin(IsolationLevel.ReadCommitted);
which works. (I can see this using NHibernate Profiler)
The problem is now I am using sharp architecture and transaction.begin is called inside that framework and I am having trouble rebuilding it.
Is there a way to do this that works without explicitly setting it when you begin a transaction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确定是这样吗?如果您只是根据 NProf 告诉您的内容来验证隔离级别;这可能是个问题。请记住,NHProf 仅报告 NHibernate 中的日志记录基础设施为其提供的内容。当您使用默认值打开事务时,也许不会发送隔离级别消息?这可能可以通过调查 NHibernate 源代码来验证。
我建议在得出这没有按预期工作的结论之前使用替代方法来验证事务级别(也许是 SQL Profiler?)。
编辑:
我已经查看了 NHibernate 源代码,并且可以验证我上面的预感。如果您查看AdoTransaction 源,您会注意到,当事务在未指定特定隔离级别的情况下启动时,它会记录 IsolationLevel.Unspecified 的隔离级别。
然而,实际的事务是用配置中指定的隔离级别开始的,如下所示:
因此,在这种情况下,NHProf 似乎并不完全准确。
更新:
看来这个问题已经在 NHibernate 的 trunk 版本中得到了修复,所以我猜这对于 NHibernate 3.xx 来说不再是问题了。
Are you certain that this is the case? If you're only verifying the isolation level by what NHProf is telling you; that could be a problem. Remember that NHProf is only reporting what the logging infrastructure in NHibernate feeds it. Perhaps the isolation level message isn't sent when you open a transaction with the default? This could probably be verified by investigating the NHibernate source.
I would suggest using an alternate means to verify the transaction level (perhaps SQL Profiler?) before concluding that this isn't working as expected.
Edit:
I've had a look at the NHibernate source and can verify my hunch above. If you have a look at the AdoTransaction source you'll note that it is logging an isolation level of IsolationLevel.Unspecified when a transaction is started without specifying a specific isolation level.
However, the actual transaction is being started with the isolation level specified in the config a few lines down as such:
So, it would seem that NHProf is not being entirely accurate in this instance.
Update:
It appears this has been fixed in the trunk version of NHibernate, so I'm guessing this is no longer an issue with NHibernate 3.xx.
看起来你的属性设置应该被称为 hibernate.connection.isolation...
问候
乔恩
Looks like your property setting should be called hibernate.connection.isolation...
Regards
Jon