spring事务隔离级别

xjpcj 2009-08-24 05:23:32
spring中事务隔离等级:
1、Serializable:最严格的级别,事务串行执行,资源消耗最大;

2、REPEATABLE READ:保证了一个事务不会修改已经由另一个事务读取但未提交(回滚)的数据。避免了“脏读取”和“不可重复读取”的情况,但是带来了更多的性能损失。

3、READ COMMITTED:大多数主流数据库的默认事务等级,保证了一个事务不会读到另一个并行事务已修改但未提交的数据,避免了“脏读取”。该级别适用于大多数系统。

4、Read Uncommitted:保证了读取过程中不会读取到非法数据

那怎么在spring配置文件中设置事务的隔离等级?找了很久了,网上都是说些事务的等级和传播
也没介绍怎么实现。
...全文
2730 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yjailj 2009-08-25
  • 打赏
  • 举报
回复
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED" isolation="READ_COMMITTED" />
</tx:attributes>
</tx:advice>
<!--
隔离级别每个数据库都不一样,如果不指定这个属性的话,就是 default
sql Server , Oracle的默认隔离级别为: Read Commited
MySQL 的默认隔离级别为 Repeatable Read
-->
<aop:config>
<aop:pointcut id="services" expression="execution(* com.service.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="services" />
</aop:config>

LZ 最好自己 试一下,这些东西不要 总是看网上查到的东西,并不是那么可靠
很多时候,大多数人都不知道怎么回事,只是只知道这么做,习惯了这么做,也只会这么做
LZ 发这个贴,也不只是想 看其他人(平时.一般.习惯)的做法吧 ?
xiaozejun 2009-08-24
  • 打赏
  • 举报
回复
我发一个spring2.0的事务配置管理文件 楼主自己看一下:

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<!-- 这个是spring2.0的配置方式,必须修改头文件,加入schema -->
<tx:advice id="myadvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" read-only="false"/>
<tx:method name="save*" propagation="REQUIRED" read-only="false"/>
<tx:method name="update*" propagation="REQUIRED" read-only="false"/>
<tx:method name="*" propagation="REQUIRED" read-only="true"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="mypointcut" expression="execution(* cn.xiaozejun.biz.imp.*.*(..))"/>
<aop:advisor advice-ref="myadvice" pointcut-ref="mypointcut"/>
</aop:config>

当前配置文件的文件头 spring2.0

<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
Goblin_SSD 2009-08-24
  • 打赏
  • 举报
回复
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>

在method中配置那哪些方法被管理

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧