Transaction rolled back because it has been marked as rollback-only

Posted x_k

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Transaction rolled back because it has been marked as rollback-only相关的知识,希望对你有一定的参考价值。

 Transaction rolled back because it has been marked as rollback-only

在工作的过程中,需要改动前人的代码,修改完毕之后总是报这个错误。 搜索了一番,原因是使用Spring事务管理的时候,某个子service回滚了事务,导致最外层的service也回滚了事务,debug查看外层service status也没有设置回滚。
代码结构:org.springframework.transaction.support.TransactionTemplate
transactionTemplate.execute(new TransactionCallback<Object>() 
                // 事务处理
                @Override
                public Object doInTransaction(TransactionStatus status) 
                    try 
<span style="white-space:pre">			</span>// TODO service
                    catch(Exception e) 
                        status.setRollbackOnly();
                        return null;
                    
                
            );
由于最外层service过于复杂,在其调用某个service的时候回滚了,并且子service的异常也被catch到了,无法抛出,子service返回结果出错也没有处理。
service 
	try 
		goOtherService();
	catch
		status.setRollbackOnly();
	



goOtherService()
	try 
		doService();
	catch
		mystatus.setRollbackOnly();
	


以上是关于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

解决使用JUNIT测试DAO事务一直ROLL BACK问题

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