SSM-MyBatis-09:Mybatis中SqlSession的close为什么能造成事务的回滚
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥-------------
经过上几次的查找,笔者我就简单的说一下查找的思路,留给读者自己实践
同样找到sqlsession的实现类,----DefaltSqlSession,找它的close方法
public void close() {
try {
this.executor.close(this.isCommitOrRollbackRequired(false));
this.closeCursors();
this.dirty = false;
} finally {
ErrorContext.instance().reset();
}
}
executor执行器的close方法里面的这个方法,传入false
private boolean isCommitOrRollbackRequired(boolean force) {
return !this.autoCommit && this.dirty || force;
}
根据上一篇博客写的,他们三个逻辑运算符的优先级 &&>||>!
得到值为true
看executor.close(boolean XXX)的方法,同样找他实现类BaseExecutor
public void close(boolean forceRollback) {
try {
try {
this.rollback(forceRollback);
} finally {
if(this.transaction != null) {
this.transaction.close();
}
}
} catch (SQLException var11) {
log.warn("Unexpected exception on closing transaction. Cause: " + var11);
} finally {
this.transaction = null;
this.deferredLoads = null;
this.localCache = null;
this.localOutputParameterCache = null;
this.closed = true;
}
}
从头开始看,rollback(true)这一行
public void rollback(boolean required) throws SQLException {
if(!this.closed) {
try {
this.clearLocalCache();
this.flushStatements(true);
} finally {
if(required) {
this.transaction.rollback();
}
}
}
}
finally中是什么事物的回滚啊,这就真相大白
SqlSession中的close在底层调用了事务的回滚的方法,当然会造成事务的回滚啊~~~~~~
SSM-MyBatis-09:Mybatis中SqlSession的close为什么能造成事务的回滚的更多相关文章
- spring + mybatis 注解式事务不回滚的原因分析 @Transactional
在一个项目中发现spring的事务无法回滚. DEBUG: org.mybatis.spring.SqlSessionUtils - SqlSession [org.apache.ibatis.ses ...
- spring + myBatis 常见错误:注解事务不回滚
最近项目在用springMVC+spring+myBatis框架,在配置事务的时候发现一个事务不能回滚的问题. 刚开始配置如下:springMVC.xml配置内容: spring.xml配置内容 从上 ...
- springmvc mybatis 声明式事务管理回滚失效,(checked回滚)捕捉异常,传输错误信息
一.知识点及问题 后端框架: Spring .Spring mvc .mybatis 业务需求: client先从服务端获取用户大量信息到client,编辑完毕之后统一Post至服务端,对于数据的改动 ...
- Spring,SpringMvc配置常见的坑,注解的使用注意事项,applicationContext.xml和spring.mvc.xml配置注意事项,spring中的事务失效,事务不回滚原因
1.Spring中的applicationContext.xml配置错误导致的异常 异常信息: org.apache.ibatis.binding.BindingException: Invalid ...
- Service中事务不能回滚的解决方式(转)
1.在service方法里面如果对异常进行了捕获的话,该事务是不会进行回滚的 默认spring事务只在发生未被捕获的 runtimeexcetpion时才回滚. spr ...
- spring事务——try{...}catch{...}中事务不回滚的几种处理方式
当希望在某个方法中添加事务时,我们常常在方法头上添加@Transactional注解 @ResponseBody @RequestMapping(value = "/payment" ...
- 事务场景中,抛出异常被catch后,如果需要回滚,一定要手动回滚事务
Spring使用声明式事务处理,默认情况下,如果被注解的数据库操作方法中发生了unchecked异常,所有的数据库操作将rollback:如果发生的异常是checked异常,默认情况下数据库操作还是会 ...
- spring事务——try{...}catch{...}中事务不回滚的几种处理方式(转载)
转载自 spring事务——try{...}catch{...}中事务不回滚的几种处理方式 当希望在某个方法中添加事务时,我们常常在方法头上添加@Transactional注解 @Respon ...
- 关于SSM项目注解事务不回滚的问题
<!--扫描service包(包含子包)下所有使用注解的类型--> <context:component-scan base-package="com.song.ssm.s ...
随机推荐
- table中 点击某一行变色
效果图: <html> <head> <meta http-equiv="Content-Type" content="text/html; ...
- CentOS 7下的Vim自动补齐插件YouCompleteMe安装及配置
备注:现在对于 YouCompleteMe 的安装应采用更为简单的方法,即利用 Vundle 来安装这个插件.具体方法可见: Vundle 主页 YouCompleteMe 主页 而 .vimrc 的 ...
- Erlang Rebar 使用指南之三:Rebar和OTP程序约定和命令
Erlang Rebar 使用指南之三:Rebar和OTP程序约定和命令 全文目录: https://github.com/rebar/rebar/wiki 本章位置: https://github. ...
- 求二叉树深度和copy二叉树
// operatorTree.cpp // 对树的操作 #include <iostream> #include <cstdio> // 二叉树表示法 typedef str ...
- 【OpenCV学习】Kmean均值聚类对图片进行减色处理
#include <cv.h> #include <highgui.h> #include <iostream> #define MAX_CLUST ...
- 一步操作关闭iOS状态栏(电池栏)
状态栏某时也蛮碍眼的: 将其关闭很简单:打开项目的info.plist文件,添加新的属性为NO的一行 View controller-based status bar appearance : 最后结 ...
- C语言算法---求鞍点
题目:有一个3X4矩阵,要求输出其鞍点(行列均最大的值),以及它的行号和列号. int a[3][4] = {{123,94,-10,218}, {3 ...
- LeetCode(49)-Valid Parentheses
题目: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the ...
- 百度站长平台MIP
使用说明 MIP(Mobile Instant Pages - 移动网页加速器),是一套应用于移动网页的开放性技术标准.通过提供 MIP-HTML 规范.MIP-JS 运行环境以及 MIP-Cache ...
- twisted高并发库transport函数处理数据包的些许问题
还是在学校时间比较多, 能够把时间更多的花在学习上, 尽管工作对人的提升更大, 但是总是没什么时间学习, 而且工作的气氛总是很紧凑, 忙碌, 少了些许激情吧.适应就好了.延续着之前对twisted高并 ...