spring:org.springframework.transaction.UnexpectedRollbackException解决
来源:互联网 发布:手机组态软件 编辑:程序博客网 时间:2024/04/29 09:08
@Transactionalpublic boolean copyCustomerInfo(Customer customer){ …… return intsertCustomer(customer); ……}@Transactionalpublic boolean intsertCustomer(Customer customer){ …… try{ intsert1(); intsert2(); }catch (Exception e){ logger.error(e); return false; } ……}
当intsertCustomer里面抛出异常但被捕获时,理论上在copyCustomerInfo里应该返回false,但是结果并没有,页面报如下错误:
网上找了很多资料,总结主要有以下几种解决方法:
1、copyCustomerInfo方法加:
@Transactional(readOnly = true, rollbackFor = RuntimeException.class)
2、intsertCustomer方法加
@Transactional(noRollbackFor = {RuntimeException.class})
3、改配置文件
<bean id="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource" /><property name="globalRollbackOnParticipationFailure" value="false" /> <!--加入该代码,指定此参数为false--></bean>
第2种办法是绝对不能做的,因为内嵌的事务不是我写的,我只是调用了人家的方法,不方便去改人家的代码。
第3种办法,在实际项目中用也不是很方便,要是这么改了,不确定对项目别的地方是否会产生影响,结果用了第1种办法,很不幸,返回不了我想要的结果。
最后的解决办法是:
@Transactional(propagation = Propagation.NOT_SUPPORTED)public boolean copyCustomerInfo(Customer customer){ …… return intsertCustomer(customer); ……}
Propagation.NOT_SUPPORTED:以非事务方式执行操作,如果当前存在事务,就把当前事务挂起。
转载请标明原址:http://blog.csdn.net/zheng911209/article/details/50130869
0 0
- spring:org.springframework.transaction.UnexpectedRollbackException解决
- org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has
- org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has
- org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has
- org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has
- org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has
- org.springframework.transaction.CannotCreateTransactionException:
- maven构建项目引用spring找不到org.springframework.transaction
- maven构建项目引用spring找不到org.springframework.transaction
- Spring 出现Java.Lang.ClassNotFoundException: Org.Springframework.Transaction.TransactionException
- maven构建项目引用spring找不到org.springframework.transaction
- 【解决】SSH问题(四)Java.Lang.ClassNotFoundException: Org.Springframework.Transaction.TransactionException
- Spring 中配置的问题 org.springframework.transaction.interceptor.TransactionInterceptor#0
- 三大框架开发时,spring配置文件出现org.springframework.transaction.interceptor.TransactionInterceptor.invoke异常
- 关于org.springframework.transaction.CannotCreateTransactionException问题
- org.springframework.transaction.CannotCreateTransactionException: Could not open
- org.springframework.transaction.CannotCreateTransactionException: Could not open
- org.springframework.transaction.CannotCreateTransactionException: Could not open
- Java finally语句到底是在return之前还是之后执行?
- Maven创建Java工程
- iOS中Core Data的使用
- 汇编语言命令速查
- Android异步任务AsyncTask详解
- spring:org.springframework.transaction.UnexpectedRollbackException解决
- Java使用reids,以及redis与shiro集成
- QT creator 3.4.1配置arm交叉编译环境(QT5.4.2)
- intellij idea14 打印tomcat日志乱码情况解决
- IntelliJ IDEA 14 下载和注册码
- 通过MySQL慢查询日志定位执行效率低的SQL语句
- 素数问题
- 表单编辑如果不加限制,在ie浏览器中表单会读取缓存在cookies里面的数据而产生一下问题
- Go语言反射规则 - The Laws of Reflection