spring-Spring 事务嵌套问题 Propagation.REQUIRES_NEW

问题描述

Spring 事务嵌套问题 Propagation.REQUIRES_NEW
 @Transactional(propagation=Propagation.REQUIRED)    public void insertEmploye(Employe emp) {        this.getSqlSession().insert(""insert"" emp);        this.updateDep(emp);        throw new Exception(""My Exception"");    }    @Transactional(propagation=Propagation.REQUIRES_NEW)    public void updateDep(Employe emp){        this.getSqlSession().update(""updateCount"" emp);    }

请问为什么updatedCount没有更新 Propagation.REQUIRES_NEW 不是启动新的事务 隔离外围的吗?

解决方案

这个update当然不可以了!
第一个insert在一个事务里,插入了记录,但还没提交
然后另一个新事务,重更新刚插入的记录,在这个新事务里,根本无法看到还未提交的insert记录,自然无法更新。

你这个update明显就不应该要求新事务,这样就没问题了。

如果要求新事务,你不等public void insertEmploye(Employe emp)这个方法返回,也就是事务提交到数据库,
再执行update才能更新新插入的记录。

解决方案二:
不明白说的什么意思,是insert成功,没有update么

解决方案三:
如果这两个方法你是写在一个Bean里面的开启事物是REQUIRED,那调用还是REQUIRED,你可以吧REQUIRES_NEW的方法写的另一个service
中。这样才能自治。同时,spring默认是对unchecked事物回滚的。

时间: 2024-08-20 00:40:43

spring-Spring 事务嵌套问题 Propagation.REQUIRES_NEW的相关文章

关于spring注解事务传播机制的REQUIRED和REQUIRES_NEW

问题描述 关于spring注解事务传播机制的REQUIRED和REQUIRES_NEW 这是有注解REQUIRED的方法: @Transactional(propagation=Propagation.REQUIRES_NEW) public void updateUserRequired(int sid) { User user = new User(); User user1 = null; user1=getUserInfo("1", null); user.setID(&quo

spring配置和注解事务同时存在导致的事务嵌套

首先先看配置文件:   [html] view plaincopy   <!-- hibernate -->       <bean id="sessionFactory"           class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">           <property name="dataSource" ref=&qu

spring注解事务

使用步骤: 步骤一.在spring配置文件中引入<tx:>命名空间 <beans xmlns="http://www.springframework.org/schema/beans"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:tx="http://www.springframework.org/schema/tx"  xsi:schemaLoca

分布式事务系列(1.2)Spring的事务体系

1 系列目录 分布式事务系列(开篇)提出疑问和研究过程 分布式事务系列(1.1)Spring事务管理器PlatformTransactionManager源码分析 分布式事务系列(1.2)Spring事务体系 分布式事务系列(2.1)分布式事务模型与接口定义 分布式事务系列(3.1)jotm的分布式案例 分布式事务系列(3.2)jotm分布式事务源码分析 分布式事务系列(4.1)Atomikos的分布式案例 2 三种事务模型 三种事务模型如下: 本地事务模型 编程式事务模型 声明式事务模型 先来

Spring Mybaties事务的困惑!求解!!

问题描述 Spring对service事务的配置<tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><tx:method name="find*" propagation="REQUIRED" read-only="true" /><tx:method na

spring的事务

Chapter 1. Spring中的事务控制(Transacion Management with Spring) Table of Contents 1.1. 有关事务(Transaction)的楔子 1.1.1. 认识事务本身 1.1.2. 初识事务家族成员 1.2. 群雄逐鹿下的Java事务管理 1.2.1. Java平台的局部事务支持 1.2.2. Java平台的分布式事务支持 1.2.2.1. 基于JTA的分布式事务管理 1.2.2.1.1. JTA编程事务管理 1.2.2.1.2.

【spring源码学习】spring的事务管理的源码解析

[一]spring事务管理(1)spring的事务管理,是基于aop动态代理实现的.对目标对象生成代理对象,加入事务管理的核心拦截器==>org.springframework.transaction.interceptor.TransactionInterceptor.===>spring事务管理的核心拦截器===>需要配置的数据项:事务管理机制配置属性的查找类transactionAttributeSource,事务管理的核心处理器PlatformTransactionManager

spring 事务 回滚-spring @Transactional 事务不能回滚

问题描述 spring @Transactional 事务不能回滚 在spring的配置文件里配置如下: <!-- enable the configuration of transactional behavior based on annotations --> <tx:annotation-driven transaction-manager="txManager"/> <!-- a PlatformTransactionManager is sti

CSDN上看到的一篇有关Spring JDBC事务管理的文章(内容比较全) (转)

  JDBC事务管理 Spring提供编程式的事务管理(Programmatic transaction manage- ment)与声明式的事务管理(Declarative transaction management),为不同的事务实现提供了一致的编程模型,这节以JDBC事务为例,介绍Spring的事务管理.  5.3.1  Spring对事务的支持 事务是一组原子(Atomic)操作的工作单元,以数据库存取的实例来说,就是一组SQL指令,这一组SQL指令必须全部执行成功,若因为某个原因未全