Transaction rolled back because it has been marked as rollback-only
Posted ssskkk
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Transaction rolled back because it has been marked as rollback-only相关的知识,希望对你有一定的参考价值。
出现这种错误的原因
1.接口A 调用了接口B
2.接口B报异常了,没有在B里面进行try catch捕获
3.接口A对 接口B进行了try catch捕获
因为接口B报异常 会把当前事物A接口的事物(如果B没有开启新的事物) 标志成rollback-only
然后因为接口A对B进行了try catch 所以接口A会一直往下走,等接口结束commit的时候会报错
org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has been marked as rollback-only
因为A的事物 被B标志成rollback-only了
解决办法
1.B接口里面就对异常做try catch处理
2.B接口里面新开一个事物
3.不对接口B进行try catch处理 这样会自动把B的错误抛出来,而不是报上面那个错
一直以为 遇到异常 try catch 不会影响到当前的事物,但是Spring管理的事物,并不是这样。这个问题 是别人跟了半天源码才帮我解决
所以,有时间跟一跟框架的源码 才能更好的理解框架 而不是花大量时间去研究怎么使用框架
以上是关于Transaction rolled back because it has been marked as rollback-only的主要内容,如果未能解决你的问题,请参考以下文章
Transaction rolled back because it has been marked as rollback-only
Spring事务管理报错Transaction rolled back because it has been marked as rollback-only
Script:when transaction will finish rollback
pip install报错Can't roll back cryptography; was not uninstalled
Unexpected update count received. Changes will be rolled back. SQL: DELETE FROM `myproject`.`role_mo