文档章节

Spring事务传播

Joey_T
 Joey_T
发布于 2015/10/10 10:43
字数 653
阅读 4
收藏 1

事务传播在org.springframework.transaction.TransactionDefinition中定义

PROPAGATION_REQUIRED

Support a current transaction; create a new one if none exists. Analogous to the EJB transaction attribute of the same name.

This is typically the default setting of a transaction definition, and typically defines a transaction synchronization scope.

支持当前事务。如果当前没有事务则创建一个新的事务。

这是事务定义的默认设置,并且定义了一个典型的事务同步域。

PROPAGATION_SUPPORTS

Support a current transaction; execute non-transactionally if none exists. Analogous to the EJB transaction attribute of the same name.

NOTE: For transaction managers with transaction synchronization, PROPAGATION_SUPPORTS is slightly different from no transaction at all, as it defines a transaction scope that synchronization might apply to. As a consequence, the same resources (a JDBC Connection, a Hibernate Session, etc) will be shared for the entire specified scope. Note that the exact behavior depends on the actual synchronization configuration of the transaction manager!

In general, use PROPAGATION_SUPPORTS with care! In particular, do not rely on PROPAGATION_REQUIRED or PROPAGATION_REQUIRES_NEW within a PROPAGATION_SUPPORTS scope (which may lead to synchronization conflicts at runtime). If such nesting is unavoidable, make sure to configure your transaction manager appropriately (typically switching to "synchronization on actual transaction").

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

PROPAGATION_MANDATORY

Support a current transaction; throw an exception if no current transaction exists. Analogous to the EJB transaction attribute of the same name.

Note that transaction synchronization within a PROPAGATION_MANDATORY scope will always be driven by the surrounding transaction.

支持当前事务,如果当前不存在事务,就抛异常。

PROPAGATION_REQUIRES_NEW

Create a new transaction, suspending the current transaction if one exists. Analogous to the EJB transaction attribute of the same name.

NOTE: Actual transaction suspension will not work out-of-the-box on all transaction managers. This in particular applies to org.springframework.transaction.jta.JtaTransactionManager, which requires the javax.transaction.TransactionManager to be made available it to it (which is server-specific in standard J2EE).

A PROPAGATION_REQUIRES_NEW scope always defines its own transaction synchronizations. Existing synchronizations will be suspended and resumed appropriately.

创建一个新事务。如果当前有事务就暂停它,然后创建一个新事务。

PROPAGATION_NOT_SUPPORTED

Do not support a current transaction; rather always execute non-transactionally. Analogous to the EJB transaction attribute of the same name.

NOTE: Actual transaction suspension will not work out-of-the-box on all transaction managers. This in particular applies to org.springframework.transaction.jta.JtaTransactionManager, which requires the javax.transaction.TransactionManager to be made available it to it (which is server-specific in standard J2EE).

Note that transaction synchronization is not available within a PROPAGATION_NOT_SUPPORTED scope. Existing synchronizations will be suspended and resumed appropriately.

不支持当前事务,而总是以非事务方式执行。

PROPAGATION_NEVER

Do not support a current transaction; throw an exception if a current transaction exists. Analogous to the EJB transaction attribute of the same name.

Note that transaction synchronization is not available within a PROPAGATION_NEVER scope.

不支持当前事务,如果当前有事务,就抛异常。

PROPAGATION_NESTED

Execute within a nested transaction if a current transaction exists, behave like PROPAGATION_REQUIRED else. There is no analogous feature in EJB.

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。

© 著作权归作者所有

共有 人打赏支持
Joey_T
粉丝 1
博文 44
码字总数 22290
作品 0
徐汇
程序员
Spring的事务管理难点剖析(3):事务方法嵌套调用的迷茫

Spring事务传播机制回顾 Spring事务一个被讹传很广说法是:一个事务方法不应该调用另一个事务方法,否则将产生两个事务。结果造成开发人员在设计事务方法时束手束脚,生怕一不小心就踩到地雷...

icheer
2012/07/17
0
0
spring 事务管理 2(spring的事务方法镶嵌使用,事务边界和传播性)没完

许多人认为spring一个事务方法不应该调用另一个事务方法,否则将产生两个事务,其实是没有正确理解spring的事务传播性和边界 Spring 对事务控制的支持统一在 org.springframework.transactio...

jiangtao
2012/01/09
0
0
Spring事务传播机制

概述 当我们调用一个基于Spring的Service接口方法(如UserService#addUser())时,它将运行于Spring管理的事务 环境中,Service接口方法可能会在内部调用其它的Service接口方法以共同完成一个...

rouway
2011/07/04
0
0
Struts2+Spring+Hibernate3集成

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hxdeng/article/details/52278238 1. 加入Struts2,Hibernate3.3,Spring3.3 和数据库驱动包 注意:当有包重复...

降龙十八腿
2016/08/22
0
0
Spring3事务管理——使用原始的TransactionProxyFactoryBean

Spring的早期版本用户必须通过TransactionProxyFactoryBean代理对需要事务管理的业务类进行代理,便于实施事务功能的增强。 让我们先看代码吧! 业务层代码: public interface UserScoreSe...

guanzhenxing
2014/03/28
0
0

没有更多内容

加载失败,请刷新页面

加载更多

WinDbg

参考来自:http://www.cnit.net.cn/?id=225 SRV*C:\Symbols*http://msdl.microsoft.com/download/symbols ctrl + d to open dump_file Microsoft (R) Windows Debugger Version 6.12.0002.633......

xueyuse0012
41分钟前
2
0
OSChina 周五乱弹 —— 想不想把92年的萝莉退货

Osc乱弹歌单(2018)请戳(这里) 【今日歌曲】 @罗马的王:分享松澤由美的单曲《地球ぎ》 很久没看圣斗士星矢了 《地球ぎ》- 松澤由美 手机党少年们想听歌,请使劲儿戳(这里) @开源中国首...

小小编辑
今天
11
1
springBoot条件配置

本篇介绍下,如何通过springboot的条件配置,控制Bean的创建 介绍下开发环境 JDK版本1.8 springboot版本是1.5.2 开发工具为 intellij idea(2018.2) 开发环境为 15款MacBook Pro 前言 很多时候,...

贺小五
今天
1
0
javascript source map 的使用

之前发现VS.NET会为压缩的js文添加一个与文件名同名的.map文件,一直没有搞懂他是用来做什么的,直接删除掉运行时浏览器又会报错,后来google了一直才真正搞懂了这个小小的map文件背后的巨大...

粒子数反转
昨天
1
0
谈谈如何学Linux和它在如今社会的影响

昨天,还在农耕脑力社会,今天已经人工智能技术、大数据、信息技术的科技社会了,高速开展并迅速浸透到当今科技社会的各个方面,Linux日益成为人们信息时代的到来,更加考验我们对信息的处理程...

linux-tao
昨天
1
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部