spring事务锁

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

事务的传播行为和隔离级别[transaction behavior and isolated level]

Spring中事务的定义:

一、Propagation :

key属性确定代理应该给哪个方法增加事务行为。这样的属性最重要的部份是传播行为。有以下选项可供使用:

PROPAGA TION_REQUIRED--支持当前事务,如果当前没有事务,就新建一个事务。这是最常见的选择。

PROPAGA TION_SUPPORTS--支持当前事务,如果当前没有事务,就以非事务方式执行。PROPAGA TION_MANDA TORY--支持当前事务,如果当前没有事务,就抛出异常。PROPAGA TION_REQUIRES_NEW--新建事务,如果当前存在事务,把当前事务挂起。PROPAGA TION_NOT_SUPPORTED--以非事务方式执行操作,如果当前存在事务,就把当前事务挂起。

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

很多人看到事务的传播行为属性都不甚了解,我昨晚看了j2ee without ejb的时候,看到这里也不了解,甚至重新翻起数据库系统的教材书,但是也没有找到对这个的分析。今天搜索,找到一篇极好的分析文章,虽然这篇文章是重点分析PROPAGA TION_REQUIRED 和PROPAGA TION_REQUIRED_NESTED的

解惑spring 嵌套事务

/**

* @author 王政

* @date 2006-11-24

* @note 转载自/topic/35907?page=1

*/

********TransactionDefinition 接口定义*******************

/**

* Support a current transaction, create a new one if none exists.

* Analogous to EJB transaction attribute of the same name.

*

This is typically the default setting of a transaction definition.

*/

int PROPAGATION_REQUIRED = 0;

/**

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

* Analogous to 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 scopp that synchronization will apply for.

* As a consequence, the same resources (JDBC Connection, Hibernate Session, etc)

* will be shared for the entire specified scope. Note that this depends on

* the actual synchronization configuration of the transaction manager.

* @see org.springframework.transaction.support.AbstractPlatformT ransactionManager#setT ransa ctionSynchronization

*/

int PROPAGATION_SUPPORTS = 1;

/**

* Support a current transaction, throw an exception if none exists.

* Analogous to EJB transaction attribute of the same name.

*/

int PROPAGATION_MANDATORY = 2;

/**

* Create a new transaction, suspend the current transaction if one exists.

* Analogous to EJB transaction attribute of the same name.

*

Note: Actual transaction suspension will not work on out-of-the-box

* on all transaction managers. This in particular applies to JtaT ransactionManager,

* which requires the javax.transaction.T ransactionManager to be

* made available it to it (which is server-specific in standard J2EE).

* @see org.springframework.transaction.jta.JtaT ransactionManager#setT ransactionManager */

int PROPAGATION_REQUIRES_NEW = 3;

/**

* Execute non-transactionally, suspend the current transaction if one exists.

* Analogous to EJB transaction attribute of the same name.

*

Note: Actual transaction suspension will not work on out-of-the-box

* on all transaction managers. This in particular applies to JtaT ransactionManager, * which requires the javax.transaction.T ransactionManager to be

* made available it to it (which is server-specific in standard J2EE).

* @see org.springframework.transaction.jta.JtaT ransactionManager#setT ransactionManager */

int PROPAGATION_NOT_SUPPORTED = 4;

相关文档
最新文档