`

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

阅读更多

A方法之外加有事务管理拦截器,在A方法中做一系列操作,操作过程中捕获了一个异常,因为此异常不影响业务,捕获后需要正常向下运行,最终事务管理器提交事务时报了如下错误
Transaction has been rolled back because it has been marked as rollback 
原因就是发生异常后当前的事务就被标记为rollback-only,外层事务管理器再commit时就会抛此异常,解决方法是

<bean id="transactionManager" 
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
       <property name="dataSource" ref="dataSource" />
	<property name="globalRollbackOnParticipationFailure" value="false" />
        <!--指定此参数为false-->
</bean>	

 在 org.springframework.transaction.support.AbstractPlatformTransactionManager 中有个叫

isGlobalRollbackOnParticipationFailure的参数,默认是true.

  

   源代码中写道

Switch this to "false" to let the transaction originator make the rollback decision. If a participating transaction fails with an exception, the caller can still decide to continue with a different path within the transaction. However, note that this will only work as long as all participating resources are capable of continuing towards a transaction commit even after a data access failure: This is generally not the case for a Hibernate Session, for example; neither is it for a sequence of JDBC insert/update/delete operations.

 

大意是:如果isGlobalRollbackOnParticipationFailure为false,则会让主事务决定回滚,如果当遇到exception加入事务失败时,调用者能继续在事务内决定是回滚还是继续。然而,要注意是那样做仅仅适用于在数据访问失败的情况下且只要所有操作事务能提交。

分享到:
评论

相关推荐

    springboot2.0.3+activiti.5.22.0+oracle在线流程设计器(Activiti-Modeler )整合

    在IT领域,SpringBoot、Activiti和Oracle是三个非常重要的技术组件,它们分别代表了现代企业级应用开发的三大支柱:轻量级框架、工作流引擎和关系型数据库。本项目将这三者进行了深度整合,构建了一个高效、便捷的...

    Could not roll back Hibernate transaction.doc

    Could not roll back Hibernate transaction; nested exception is org.hibernate.TransactionException: JDBC rollback failed 这表明Hibernate事务回滚操作失败,导致事务不能正确回滚。 二、问题原因 该问题的...

    微软内部资料-SQL性能优化3

    Intent locks improve performance because SQL Server examines intent locks only at the table level to determine whether a transaction can safely acquire a lock on that table. This removes the ...

    C#中调用Transaction

    本文将深入探讨“C#中调用Transaction”的相关知识点,包括事务的基本概念、事务的特性、如何在C#代码中创建和管理事务,以及与数据库交互时事务的应用。 ### 1. 事务基本概念 事务是数据库操作的一组逻辑单元,它...

    Transaction Rollback 事务 让你的对象支持事务

    难道只要数据库连接才支持事务?... 自行实现所有细节,比如说银行的提款机模拟,在Withdraw的代码中检查支取金额后的余额或者检查支取金额的大小是否超过当天限额限制,否则报错或退出当前Withdraw方法 ...

    SQL Server数据库P166 (3)ROLLBACK TRANSACTION将显式事务或隐式事务回滚到事务的结束.sql

    内容概述:SQL Server数据库相关内容,对应张磊著《SQL Server数据库应用技术项目化教程》中166页(3)ROLLBACK TRANSACTION将显式事务或隐式事务回滚到事务的结束所对应的源码。代码经个人运行后无误,如果下载后运行...

    Activity+多个Fragment开发

    你可以使用`beginTransaction()`来开始一个事务,然后通过`add()`, `replace()`, `hide()`, `show()`等方法来添加、替换或隐藏`Fragment`。最后,记得调用`commit()`来提交这些变更。 2. **Fragment的生命周期**:`...

    Introduction to Transactions

    A transaction is a program module that starts with ‘begin transaction’ statement, ...when ‘rollback transaction’ statement returns, the effect of data modifications by the Xact will have been undone.

    COS——R.log

    org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has been marked as rollback-only at org.springframework.transaction.support....

    HibernateSession , Transaction 研究

    `Session`提供了一系列的事务管理方法,如`beginTransaction()`、`commit()`和`rollback()`。 1. `beginTransaction()`:启动一个新的事务,这通常是所有数据库操作的起点。 2. `commit()`:提交当前事务,意味着...

    PLSQL.Developer(X32) v12.0.1.1814主程序+ v11中文包+keygen

    The truncate option is faster but cannot be rolled back. The Compile Invalid Objects tool now has a User Selector. PL/SQL Developer 12 now comes as a new MSI installer for interactive and silent ...

    plsqldev12.0.4.1826x32主程序+ v12中文包+keygen

    The truncate option is faster but cannot be rolled back. The Compile Invalid Objects tool now has a User Selector. PL/SQL Developer 12 now comes as a new MSI installer for interactive and silent ...

    Transaction

    在IT行业中,事务(Transaction)是数据库操作的核心概念,它确保了数据的一致性和完整性。在分布式系统和多用户环境中,事务处理对于防止数据错误和保持数据一致性至关重要。本篇文章将深入探讨“Transaction”这一...

    PLSQL.Developer(X64) v12.0.1.1814 主程序+ v11中文包+keygen

    The truncate option is faster but cannot be rolled back. The Compile Invalid Objects tool now has a User Selector. PL/SQL Developer 12 now comes as a new MSI installer for interactive and silent ...

    plsqldev12.0.4.1826x64主程序+ v12中文包+keygen

    The truncate option is faster but cannot be rolled back. The Compile Invalid Objects tool now has a User Selector. PL/SQL Developer 12 now comes as a new MSI installer for interactive and silent ...

    BURNINTEST--硬件检测工具

    - A hang on startup has been corrected. A 2 minute timeout has been added to the collection of system information. - Video playback, Hard disk and CD/DVD test 'no operations' error reporting ...

    javax.transaction-api-1.2-API文档-中文版.zip

    赠送jar包:javax.transaction-api-1.2.jar; 赠送原API文档:javax.transaction-api-1.2-javadoc.jar; 赠送源代码:javax.transaction-api-1.2-sources.jar; 赠送Maven依赖信息文件:javax.transaction-api-1.2....

    javax.transaction.jar

    【javax.transaction.jar】是Java平台上的一个核心组件,主要用于处理分布式环境中的事务管理。这个库包含了一组接口和类,这些接口和类定义了事务管理的API,使得开发者能够在Java应用程序中实现事务处理的规范。在...

Global site tag (gtag.js) - Google Analytics