热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

无法设置默认的Nhibernate隔离级别(例如通过映射)-CannotsetadefaultNhibernateisolationlevel(egviamapping)

Thishasbeenaproblemthathasexistedon3projectsforme.这对我来说已经存在于3个项目中的问题。Ihavetriedthe

This has been a problem that has existed on 3 projects for me.

这对我来说已经存在于3个项目中的问题。

I have tried the following:

我尝试过以下方法:

ReadCommitted

Set in hibernate.cfg.xml

在hibernate.cfg.xml中设置

Using fluent nhiberate:

使用流利的nhiberate:

MsSqlConfiguration.MsSql2008.IsolationLevel(IsolationLevel.ReadCommitted);

Set in global.asax.cs

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

哪个有效。 (我可以使用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.

问题是现在我使用的是尖锐的架构,并且在该框架内调用了transaction.begin,我无法重建它。

Is there a way to do this that works without explicitly setting it when you begin a transaction?

有没有办法做到这一点,无需在开始交易时明确设置它?

2 个解决方案

#1


7  

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.

你确定是这样的吗?如果您只是通过NHProf告诉您的隔离级别来验证隔离级别;这可能是个问题。请记住,NHProf仅报告NHibernate中的日志记录基础结构提供的内容。使用默认值打开事务时,可能不会发送隔离级别消息?这可以通过调查NHibernate源来验证。

I would suggest using an alternate means to verify the transaction level (perhaps SQL Profiler?) before concluding that this isn't working as expected.

我建议使用另一种方法来验证事务级别(可能是SQL事件探查器?),然后再认为这不能按预期工作。

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.

我已经看过NHibernate的源代码,可以验证我的预感。如果您查看AdoTransaction源,您会注意到它在启动事务时记录隔离级别的IsolationLevel.Unspecified而未指定特定的隔离级别。

// This is the default overload you're calling:
public void Begin()
{
Begin(IsolationLevel.Unspecified);
}

// This is the full method impl
public void Begin(IsolationLevel isolationLevel)
{
// snip....

// This is the problematic line here; it will report an isolationLevel of Unspecified.
log.Debug(string.Format("Begin ({0})", isolationLevel));

// snip...

}

However, the actual transaction is being started with the isolation level specified in the config a few lines down as such:

但是,实际事务正在使用配置中指定的隔离级别启动几行,如下所示:

if (isolatiOnLevel== IsolationLevel.Unspecified)
{
isolatiOnLevel= session.Factory.Settings.IsolationLevel;
}

So, it would seem that NHProf is not being entirely accurate in this instance.

因此,在这种情况下,似乎NHProf并不完全准确。

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.

看起来这已经在NHibernate的trunk版本中修复了,所以我猜这不再是NHibernate 3.xx的问题。

#2


0  

Looks like your property setting should be called hibernate.connection.isolation...

看起来您的属性设置应该被称为hibernate.connection.isolation ...


Regards

Jon


推荐阅读
author-avatar
DiKi造型Alen老师
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有