mysql测试spring事务是否生效
同时对三张表进行插入操作,事务保证完整性。下面进行简单测试:
1. 锁定表
锁定用户表
LOCK TABLES user WRITE;
查看表是否锁定:
show OPEN TABLES where In_use > 0;
显示被锁定的表。
2. 验证在同一session下是否可以插入操作
insert into user(userId,ip,type,terminal) values(10002,'127.0.0.1',7,'pc');
可以操作成功。
3. 启动spring应用,执行插入操作,不能成功。
4,解锁
UNLOCK TABLES;
查看被锁定的表:
show OPEN TABLES where In_use > 0;
上述表不在锁定中。
5. 调用spring应用,执行插入操作,操作可以成功。
所以,应用spring的@transactional进行事务管理是ok的。
附录:
SHOW OPEN TABLES Syntax:https://dev.mysql.com/doc/refman/5.0/en/show-open-tables.html
SHOW OPEN TABLES [{FROM | IN}db_name
]
[LIKE 'pattern
' | WHEREexpr
]
SHOW OPEN TABLES
lists the non-TEMPORARY
tables that are currently open in the table cache. SeeSection 8.4.3.1, “How MySQL Opens and Closes Tables”. The WHERE
clause can be given to select rows using more general conditions, as discussed in Section 19.18, “Extensions to SHOW Statements”.
The FROM
and LIKE
clauses may be used as of MySQL 5.0.12. The LIKE
clause, if present, indicates which table names to match. The FROM
clause, if present, restricts the tables shown to those present in the db_name
database.
SHOW OPEN TABLES
output has the following columns:
Database
The database containing the table.
Table
The table name.
In_use
The number of table locks or lock requests there are for the table. For example, if one client acquires a lock for a table using
LOCK TABLE t1 WRITE
,In_use
will be 1. If another client issuesLOCK TABLE t1 WRITE
while the table remains locked, the client will block waiting for the lock, but the lock request causesIn_use
to be 2. If the count is zero, the table is open but not currently being used.In_use
is also increased by theHANDLER ... OPEN
statement and decreased byHANDLER ... CLOSE
.Name_locked
Whether the table name is locked. Name locking is used for operations such as dropping or renaming tables.
mysql测试spring事务是否生效的更多相关文章
- 事务,Oracle,MySQL及Spring事务隔离级别
一.什么是事务: 事务逻辑上的一组操作,组成这组操作的各个逻辑单元,要么一起成功,要么一起失败. 二.事务特性(4种): 原子性 (atomicity):强调事务的不可分割:一致性 (consiste ...
- Spring事务不生效问题
事务未生效可能造成严重的数据不一致性问题,因而保证事务生效至关重要.Spring事务是通过Spring aop实现的,所以不生效的本质问题是spring aop没生效,或者说没有代理成功,所以有必要了 ...
- Spring基础系列-Spring事务不生效的问题与循环依赖问题
原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9476550.html 一.提出问题 不知道你是否遇到过这样的情况,在ssm框架中开发we ...
- MySQL与Spring事务隔离级别
https://zhuanlan.zhihu.com/p/27887568 能画第一张表,根据表描述.
- 深入理解 Spring 事务:入门、使用、原理
大家好,我是树哥. Spring 事务是复杂一致性业务必备的知识点,掌握好 Spring 事务可以让我们写出更好地代码.这篇文章我们将介绍 Spring 事务的诞生背景,从而让我们可以更清晰地了解 S ...
- [转]Spring事务嵌套引发的血案---Transaction rolled back because it has been marked as rollback-only
原文地址:https://blog.csdn.net/f641385712/article/details/80445912 1.概述 想必大家一想到事务,就想到ACID,或者也会想到CAP.但笔者今 ...
- spring事务详解(四)测试验证
系列目录 spring事务详解(一)初探事务 spring事务详解(二)简单样例 spring事务详解(三)源码详解 spring事务详解(四)测试验证 spring事务详解(五)总结提高 一.引子 ...
- 云笔记项目-Spring事务学习_测试准备
在做云笔记项目的过程中,顺便简单的学习了Spring的事务概念,业务以如果添加笔记,则增加用户星星数目作为例子,引入了事务的概念.类似注册送积分之类的,云笔记项目以增加笔记就送星星来说明事务.具体在添 ...
- spring中注解式事务不生效的问题
常用的解决方法可以百度,我针对我的问题描述一下 Mysql中InnoDB引擎才支持事务, MyISAM不支持事务. 当你尝试了各种方法解决spring中注解式事务不生效时, 一定要查看一下数据库中表的 ...
随机推荐
- 路径+DataRow+SqlPara防止sql注入
绝对路径:是从盘符开始的路径,形如C:\windows\system32\cmd.exe相对路径:是从当前路径开始的路径,假如当前路径为C:\windows要描述上述路径,只需输入system32\c ...
- C++中全局变量的声明和定义
原文链接:http://blog.csdn.net/candyliuxj/article/details/7853938 (1)编译单元(模块) 在VC或VS上编写完代码,点击编译按钮准备生成exe文 ...
- SELinux 入门
几乎可以肯定每个人都听说过 SELinux (更准确的说,尝试关闭过),甚至某些过往的经验让您对 SELinux 产生了偏见.不过随着日益增长的 0-day 安全漏洞,或许现在是时候去了解下这个在 L ...
- python pdb小结
Debug功能对于developer是非常重要的,python提供了相应的模块pdb让你可以在用文本编辑器写脚本的情况下进行debug. pdb是python debugger的简称.常用的一些命令如 ...
- JS取出两个数组的不同或相同元素
JS合并两个数组的方法 我们在项目过程中,有时候会遇到需要将两个数组合并成为一个的情况.比如: var a = [1,2,3]; var b = [4,5,6]; 有两个数组a.b,需求是将两个数组合 ...
- Idea下mybatis的错误—Module not specified
IDEA下使用maven的mybatis常见错误 错误类型一:导入项目引起的错误Module not specified 错误提示:idea Error Module not specified. 错 ...
- 消灭星星的数组高效率算法(c++代码,控制台程序)
#include <iostream> using namespace std; #define ROW 12 #define COL 10 class Star { public: en ...
- SQL 增删改查(具体)
一.增:有3种方法 1.使用insert插入单行数据: insert [into] <表名> [列名] values <列值> insert into Strdents (na ...
- Scrum中的产品需求预审
原文作者:Mike Cohn 为了保持产品待办事项(product backlog)的整洁有序,我们须要召开product backlog refinement会议(有时也叫product backl ...
- vim 基础学习之global
global命令可以在指定模式下,匹配行上进行Ex命令 使用格式: :[range]g[lobal]/{pattern}/[cmd] range-是执行范围(如果缺省,是%) global-命令关键字 ...