- 浏览: 203447 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (175)
- JAVA BASIC (34)
- 资料 (2)
- WEB (4)
- Android (2)
- DBMS (2)
- 我的小东西 (4)
- IT生活 (6)
- portal (1)
- jsp (6)
- user experience (1)
- SSH (12)
- Flex (13)
- FLEX DEBUGER does not work (1)
- teacher (1)
- tools (2)
- maven (3)
- opensource (3)
- OUTLOOK (1)
- 经验之谈 (4)
- SQL (2)
- BOOK (1)
- jprofiler (1)
- hp veer 4g (2)
- axis2 (1)
- JAVASCRIPT (8)
- httpd (2)
- Webservice (3)
- JBOSS (9)
- JPA (2)
- JSF (1)
- XMLBean (1)
- J2EE6 (1)
- apache (1)
- HTML (1)
- review (1)
- Spring (7)
- hot cache (1)
- Websphere (1)
- 软件管理 (1)
- redis (1)
- Sitemesh (1)
- JDBC (1)
- http (2)
- linux (3)
- new-framework (2)
- Log4j (3)
- JMX (1)
- springmvc (2)
- Sprint Boot (1)
- NIO (2)
- mongodb (1)
- 一个监控系统引发的学习 (1)
- kafka消息只消费一次应该怎么做 (1)
- 一眼识别程序功力 (1)
最新评论
-
tcgdy0201:
挖!博主好棒!博主好腻害!
logback.xml immediate=false 到底缓存空间是多大 -
k1280000:
jasonlong10 写道 楼主别光写报错,有没什么解决方法 ...
SpringMVC 在 Jboss 下会报的 warn -
jasonlong10:
楼主别光写报错,有没什么解决方法啊?
SpringMVC 在 Jboss 下会报的 warn -
rtttyu23:
不错,没报错了...这些配置的文件真麻烦,不深入了解,配置的很 ...
Error creating bean with name '_messageBrokerDefaultHandlerMapping': Initializa -
thinkcq168:
这样还是不可以,还是报错,我也有同样的错误,求高手!
Error creating bean with name '_messageBrokerDefaultHandlerMapping': Initializa
一、什么是Java事务
通常的观念认为,事务仅与数据库相关。
事务必须服从ISO/IEC所制定的ACID原则。ACID是原子性(atomicity)、一致性(consistency)、隔离性(isolation)和持久性(durability)的缩写。事务的原子性表示事务执行过程中的任何失败都将导致事务所做的任何修改失效。一致性表示当事务执行失败时,所有被该事务影响的数据都应该恢复到事务执行前的状态。隔离性表示在事务执行过程中对数据的修改,在事务提交之前对其他事务不可见。持久性表示已提交的数据在事务执行失败时,数据的状态都应该正确。
通俗的理解,事务是一组原子操作单元,从数据库角度说,就是一组SQL指令,要么全部执行成功,若因为某个原因其中一条指令执行有错误,则撤销先前执行过的所有指令。更简答的说就是:要么全部执行成功,要么撤销不执行。
既然事务的概念从数据库而来,那Java事务是什么?之间有什么联系?
实际上,一个Java应用系统,如果要操作数据库,则通过JDBC来实现的。增加、修改、删除都是通过相应方法间接来实现的,事务的控制也相应转移到Java程序代码中。因此,数据库操作的事务习惯上就称为Java事务。
二、为什么需要事务
事务是为解决数据安全操作提出的,事务控制实际上就是控制数据的安全访问。具一个简单例子:比如银行转帐业务,账户A要将自己账户上的1000元转到B账户下面,A账户余额首先要减去1000元,然后B账户要增加1000元。假如在中间网络出现了问题,A账户减去1000元已经结束,B因为网络中断而操作失败,那么整个业务失败,必须做出控制,要求A账户转帐业务撤销。这才能保证业务的正确性,完成这个操走就需要事务,将A账户资金减少和B账户资金增加方到一个事务里面,要么全部执行成功,要么操作全部撤销,这样就保持了数据的安全性。
三、Java事务的类型
Java事务的类型有三种:JDBC事务、JTA(Java Transaction API)事务、容器事务。
1、JDBC事务
JDBC 事务是用 Connection 对象控制的。JDBC Connection 接口( java.sql.Connection )提供了两种事务模式:自动提交和手工提交。 java.sql.Connection 提供了以下控制事务的方法:
public void setAutoCommit(boolean)
public boolean getAutoCommit()
public void commit()
public void rollback()
使用 JDBC 事务界定时,您可以将多个 SQL 语句结合到一个事务中。JDBC 事务的一个缺点是事务的范围局限于一个数据库连接。一个 JDBC 事务不能跨越多个数据库。......
This section describes some semantics of transaction propagation in Spring. Please note that this section is not an introduction to transaction propagation proper; rather it details some of the semantics regarding transaction propagation in Spring.
In Spring-managed transactions, be aware of the difference between physical and logical transactions, and how the propagation setting applies to this difference.
11.5.7.1 Required
This section describes some semantics of transaction propagation in Spring. Please note that this section is not an introduction to transaction propagation proper; rather it details some of the semantics regarding transaction propagation in Spring.
In Spring-managed transactions, be aware of the difference between physical and logical transactions, and how the propagation setting applies to this difference.
When the propagation setting is PROPAGATION_REQUIRED
, a logical transaction scope is created for each method upon which the setting is applied. Each such logical transaction scope can determine rollback-only status individually, with an outer transaction scope being logically independent from the inner transaction scope. Of course, in case of standard PROPAGATION_REQUIRED
behavior, all these scopes will be mapped to the same physical transaction. So a rollback-only marker set in the inner transaction scope does affect the outer transaction's chance to actually commit (as you would expect it to).
However, in the case where an inner transaction scope sets the rollback-only marker, the outer transaction has not decided on the rollback itself, and so the rollback (silently triggered by the inner transaction scope) is unexpected. A corresponding UnexpectedRollbackException
is thrown at that point. This is expected behavior so that the caller of a transaction can never be misled to assume that a commit was performed when it really was not. So if an inner transaction (of which the outer caller is not aware) silently marks a transaction as rollback-only, the outer caller still calls commit. The outer caller needs to receive an UnexpectedRollbackException
to indicate clearly that a rollback was performed instead.
When the propagation setting is PROPAGATION_REQUIRED
, a logical transaction scope is created for each method upon which the setting is applied. Each such logical transaction scope can determine rollback-only status individually, with an outer transaction scope being logically independent from the inner transaction scope. Of course, in case of standard PROPAGATION_REQUIRED
behavior, all these scopes will be mapped to the same physical transaction. So a rollback-only marker set in the inner transaction scope does affect the outer transaction's chance to actually commit (as you would expect it to).
However, in the case where an inner transaction scope sets the rollback-only marker, the outer transaction has not decided on the rollback itself, and so the rollback (silently triggered by the inner transaction scope) is unexpected. A corresponding UnexpectedRollbackException
is thrown at that point. This is expected behavior so that the caller of a transaction can never be misled to assume that a commit was performed when it really was not. So if an inner transaction (of which the outer caller is not aware) silently marks a transaction as rollback-only, the outer caller still calls commit. The outer caller needs to receive an UnexpectedRollbackException
to indicate clearly that a rollback was performed instead.
When the propagation setting is PROPAGATION_REQUIRED
, a logical transaction scope is created for each method upon which the setting is applied. Each such logical transaction scope can determine rollback-only status individually, with an outer transaction scope being logically independent from the inner transaction scope. Of course, in case of standard PROPAGATION_REQUIRED
behavior, all these scopes will be mapped to the same physical transaction. So a rollback-only marker set in the inner transaction scope does affect the outer transaction's chance to actually commit (as you would expect it to).
However, in the case where an inner transaction scope sets the rollback-only marker, the outer transaction has not decided on the rollback itself, and so the rollback (silently triggered by the inner transaction scope) is unexpected. A corresponding UnexpectedRollbackException
is thrown at that point. This is expected behavior so that the caller of a transaction can never be misled to assume that a commit was performed when it really was not. So if an inner transaction (of which the outer caller is not aware) silently marks a transaction as rollback-only, the outer caller still calls commit. The outer caller needs to receive an UnexpectedRollbackException
to indicate clearly that a rollback was performed instead.
- read dirty data : tx1 read tx2's update but not commited data
- can not re-readable : tx1 can not get the same return data from one field (tx1 can read the updated and commited data from tx2 )
- imaginary read : tx1 read the data from which tx2 inserted and commited
------------------------------------------------------
- if i use try-catch surround the below code snippet the spring container can not do the controll of transaction , if not spring container can do it for us. just throw !!!
@Transactional(rollbackFor=Exception.class)
public void delPerson(Integer id) throws Exception {
try{
String sql = "delete from person where id = ?";
jdbcTemplate.update(sql, new Object[] {id}, new int []{java.sql.Types.INTEGER});
throw new Exception ( "Exception");
}catch(){}
}
-----------------------------------------------------
- Spring 事务详解
- http://developer.51cto.com/art/200906/129854.htm
发表评论
-
log4j.properties 使用 (转)
2012-06-07 16:40 714(转自)http://www.blogjava.net/hwp ... -
Struts2 ognl中的#、%和$符号用法说明 (转)
2012-06-06 16:56 622转( Str ... -
Struts2 Session 使用和安全
2012-06-05 15:12 1240When your Action class needs to ... -
Message Resource Files
2012-05-31 11:09 788详见教程 message resourc ... -
Struts2 & Servlet 线程,生命周期小理解
2012-05-11 11:43 771... -
Dynamic Proxy
2011-09-19 14:58 780http://www.javaworld.com/jav ... -
spring learn experience
2011-09-17 21:22 725org.springframework.context ... -
spring beanfactory
2011-07-06 16:01 9191. beanfactory create beans in ... -
hibernate 教程
2011-05-14 22:15 1091原理: http://wenku.baidu.com/vie ... -
struts2 +spring 教程
2011-05-14 21:10 538http://hi.baidu.com/baileyfu/bl ... -
learning of struts 2
2011-04-18 00:06 699today , I am re-learning the St ...
相关推荐
【javax.transaction.jar】是Java平台上的一个核心组件,主要用于处理分布式环境中的事务管理。这个库包含了一组接口和类,这些接口和类定义了事务管理的API,使得开发者能够在Java应用程序中实现事务处理的规范。在...
javax.transaction.xa javax.xml javax.xml.datatype javax.xml.namespace javax.xml.parsers javax.xml.transform javax.xml.transform.dom javax.xml.transform.sax javax.xml.transform.stream javax....
【标题】"com.qz.transaction.MainActivity 非常好的源码资源" 提供的是一个关于Android应用程序源码的分析和学习素材,其中`MainActivity`是Android应用中的主要入口类,通常承载了应用的主要功能和界面展示。...
stock-transaction.csv
解决castle事务处理framework4.0异常,反编译修改后的dll集合,castle+Ibatis.NET集成dll,包含事务处理相关,...Castle.Services.Transaction.dll Castle.Windsor.dll IBatisNet.Common.dll IBatisNet.DataMapper.dll
org.springframework.transaction-3.0.0.M4.jar
org.springframework.transaction-3.2.4.RELEASE.jar,最新版的org.springframework.transaction,Wed Aug 07 16:44:37 GMT+01:00 2013
fescar-transaction.zip文件是一个包含Fescar分布式事务实现案例的压缩包,可以帮助开发者快速理解和应用Fescar。 Fescar的核心设计目标是提供简单易用、高性能、高可用的分布式事务服务,以解决在大规模分布式系统...
本项目"基于Hyperf的TCC分布式事务-tcc-transaction.zip"提供了在Hyperf框架下实现TCC事务的示例,帮助开发者理解和应用TCC模式。 首先,我们需要了解Hyperf。Hyperf是一款基于Swoole 4.4+开发的高性能、全异步的...
jar包,官方版本,自测可用
《SAP Transaction Codes 2010》是一本由Arshad Khan编写的关于SAP事务代码的参考手册,特别适合于使用SAP业务软件的各类用户,包括普通终端用户、高级用户、领域专家(Subject Matter Experts,SMEs)、项目团队...
java运行依赖jar包
Could not roll back Hibernate transaction; nested exception is org.hibernate.TransactionException: JDBC rollback failed 这表明Hibernate事务回滚操作失败,导致事务不能正确回滚。 二、问题原因 该问题的...
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.interceptor.TransactionInterceptor#0': Error setting property values; nested ...
赠送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....
Transaction.class
transaction.sol
javax.transaction.xa javax.xml javax.xml.bind javax.xml.bind.annotation javax.xml.bind.annotation.adapters javax.xml.bind.attachment javax.xml.bind.helpers javax.xml.bind.util javax.xml.crypto...
org.springframework.transaction-3.2.2.RELEASE最新版本
javax.transaction.xa javax.xml javax.xml.bind javax.xml.bind.annotation javax.xml.bind.annotation.adapters javax.xml.bind.attachment javax.xml.bind.helpers javax.xml.bind.util javax.xml.crypto...