How do I override the default isolation level when using the Transaction attribute in Spring.Net

我的未来我决定 提交于 2019-12-13 02:03:06

问题


When using the Transaction() attribute on a method the default isolation level is ReadCommitted. What I want to do is set the default isolation level to ReadUncommitted in the Spring.NET config ( so as not to modify all the Transaction attribute definitions that exist currently)

How do I do it ? Can it be done with Spring.NET 1.2 ?

I've tried to follow the documentation using tx:advice etc to no avail.

I've even stepped in to the code of Spring with Reflector but all I seem to understand from that, is that Spring simply reads the settings from the Attribute declaration on the method.

Can it be done or am I going to have to go through the code and modify the attribute where necessary?


回答1:


I usually use e.g.:

[Transaction( IsolationLevel.ReadUncommitted )]

on my repository methods. And it works in conjuction with <tx:attribute-driven transaction-manager="HibernateTransactionManager"/>.

<object
  name="HibernateTransactionManager"
  type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate32"
  dependency-check="none">
  <property name="DbProvider" ref="MsSqlDbProvider"/>
  <property name="SessionFactory" ref="SessionFactory"/>
</object>



回答2:


You should be able to create your own transaction interceptor that extends the standard transaction interceptor. And then hook up that one using ObjectNameAutoProxyCreator instead of the TransactionProxyFactoryObject that you referenced.



来源:https://stackoverflow.com/questions/7728989/how-do-i-override-the-default-isolation-level-when-using-the-transaction-attribu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!