博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring事务传播
阅读量:7020 次
发布时间:2019-06-28

本文共 1628 字,大约阅读时间需要 5 分钟。

  hot3.png

事务传播的几种类型

参考代码文件:

spring-tx-4.2.0.RELEASE.jar

org.springframework.transaction.TransactionDefinition

  • (1) PROPAGATION_REQUIRED

    Support a current transaction; create a new one if none exists. This is typically the default setting of a transaction definition, and typically defines a transaction synchronization scope.

    如果当前没有事务,就新建一个事务,如果已经存在一个事务中,加入到这个事务中。这是最常见的选择。

  • (2) PROPAGATION_SUPPORTS

    Support a current transaction; execute non-transactionally if none exists.

    支持当前事务,如果当前没有事务,就以非事务方式执行。

  • (3) PROPAGATION_MANDATORY

    Support a current transaction; throw an exception if no current transaction exists.

    使用当前的事务,如果当前没有事务,就抛出异常。

  • (4) PROPAGATION_REQUIRES_NEW

    Create a new transaction, suspending the current transaction if one exists.

    新建事务,如果当前存在事务,把当前事务挂起。

  • (5) PROPAGATION_NOT_SUPPORTED

    Do not support a current transaction; rather always execute non-transactionally.

    以非事务方式执行操作,如果当前存在事务,就把当前事务挂起。

  • (6) PROPAGATION_NEVER

    Do not support a current transaction; throw an exception if a current transaction exists.

    以非事务方式执行,如果当前存在事务,则抛出异常。

  • (7) PROPAGATION_NESTED

    Execute within a nested transaction if a current transaction exists, behave like PROPAGATION_REQUIRED else.

    NOTE: Actual creation of a nested transaction will only work on specific transaction managers. Out of the box, this only applies to the JDBC org.springframework.jdbc.datasource.DataSourceTransactionManager when working on a JDBC 3.0 driver. Some JTA providers might support nested transactions as well.

    如果当前存在事务,则在嵌套事务内执行。如果当前没有事务,则执行与PROPAGATION_REQUIRED类似的操作。

    当使用PROPAGATION_NESTED时,底层的数据源必须基于JDBC 3.0,并且实现者需要支持保存点事务机制。

转载于:https://my.oschina.net/import/blog/756261

你可能感兴趣的文章
【数据泵】EXPDP导出表结构(真实案例)
查看>>
LINUX errno大全
查看>>
Bootstrap<基础六> 表单
查看>>
[20170425]变态的windows批处理1.txt
查看>>
《Programming WPF》翻译 第9章 2.选择一个基类
查看>>
nginx+tomcat+redis完成session共享
查看>>
Swift游戏实战-跑酷熊猫 07 平台的移动
查看>>
Web---字节输出流和字符输出流的共存问题、转发、重定向、请求包含知识点讲解...
查看>>
【迷你微信】基于MINA、Hibernate、Spring、Protobuf的即时聊天系统:3.技术简介之MinaFilter——LoggingFilter (转)...
查看>>
java中的取整(/)和求余(%)
查看>>
WPF换肤之三:WPF中的WndProc
查看>>
ArcGIS中如何导出单个矢量要素图形
查看>>
微信支付curl出错及错误码解决方案
查看>>
微信支付开发(5) 扫码并输入金额支付
查看>>
推荐一个计算机视觉图书:python计算机视觉编程
查看>>
Simple iPhone Keychain Access
查看>>
360,京东,在线编程题
查看>>
Large-Scale Video Classification 2017 比赛总结
查看>>
实现celery中出现拥挤队列时,及时发邮件通知
查看>>
飞天遁地、来去自如?Oracle数据库秉承技术当先,用户也来说说看
查看>>