同时对三张表进行插入操作,事务保证完整性。下面进行简单测试:

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' | WHERE expr]

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_namedatabase.

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 WRITEIn_use will be 1. If another client issues LOCK TABLE t1 WRITE while the table remains locked, the client will block waiting for the lock, but the lock request causes In_use to be 2. If the count is zero, the table is open but not currently being used. In_use is also increased by the HANDLER ... OPENstatement and decreased by HANDLER ... CLOSE.

  • Name_locked

    Whether the table name is locked. Name locking is used for operations such as dropping or renaming tables.

mysql测试spring事务是否生效的更多相关文章

  1. 事务,Oracle,MySQL及Spring事务隔离级别

    一.什么是事务: 事务逻辑上的一组操作,组成这组操作的各个逻辑单元,要么一起成功,要么一起失败. 二.事务特性(4种): 原子性 (atomicity):强调事务的不可分割:一致性 (consiste ...

  2. Spring事务不生效问题

    事务未生效可能造成严重的数据不一致性问题,因而保证事务生效至关重要.Spring事务是通过Spring aop实现的,所以不生效的本质问题是spring aop没生效,或者说没有代理成功,所以有必要了 ...

  3. Spring基础系列-Spring事务不生效的问题与循环依赖问题

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9476550.html 一.提出问题 不知道你是否遇到过这样的情况,在ssm框架中开发we ...

  4. MySQL与Spring事务隔离级别

    https://zhuanlan.zhihu.com/p/27887568 能画第一张表,根据表描述.

  5. 深入理解 Spring 事务:入门、使用、原理

    大家好,我是树哥. Spring 事务是复杂一致性业务必备的知识点,掌握好 Spring 事务可以让我们写出更好地代码.这篇文章我们将介绍 Spring 事务的诞生背景,从而让我们可以更清晰地了解 S ...

  6. [转]Spring事务嵌套引发的血案---Transaction rolled back because it has been marked as rollback-only

    原文地址:https://blog.csdn.net/f641385712/article/details/80445912 1.概述 想必大家一想到事务,就想到ACID,或者也会想到CAP.但笔者今 ...

  7. spring事务详解(四)测试验证

    系列目录 spring事务详解(一)初探事务 spring事务详解(二)简单样例 spring事务详解(三)源码详解 spring事务详解(四)测试验证 spring事务详解(五)总结提高 一.引子 ...

  8. 云笔记项目-Spring事务学习_测试准备

    在做云笔记项目的过程中,顺便简单的学习了Spring的事务概念,业务以如果添加笔记,则增加用户星星数目作为例子,引入了事务的概念.类似注册送积分之类的,云笔记项目以增加笔记就送星星来说明事务.具体在添 ...

  9. spring中注解式事务不生效的问题

    常用的解决方法可以百度,我针对我的问题描述一下 Mysql中InnoDB引擎才支持事务, MyISAM不支持事务. 当你尝试了各种方法解决spring中注解式事务不生效时, 一定要查看一下数据库中表的 ...

随机推荐

  1. Python(四) 分支、循环、条件与枚举

    一.什么是表达式 表达式(Expression)是运算符(operator)和操作数(operand)所构成的序列 二.表达式的优先级 三.表达式优先级练习 优先级同级 从左往右计算 1 or 2 a ...

  2. BFS(广度优先搜索)

    Catch That Cow Farmer John has been informed of the location of a fugitive cow and wants to catch he ...

  3. Microsoft office2016(专业增强版) 安装错误,报CRT(KB2999226)

    对着这个错误的出现,网上有解释,这里不多说(实际是我没有找到比较靠谱的说法..),跟Window Update这个服务有关. 首先打开”Windows人为管理器”->"服务" ...

  4. mescroll报错

    1.Cannot read property 'insertBefore' of null:说明你的容器id未找到,应确认你的容器id名与你NEW的容器名一致:

  5. 学习参考《矩阵分析与应用(第二版)张贤达》PDF

    要想深入理解机器学习,或者对人工智能的某个领域有所研究,都必须掌握矩阵及其应用. 学习<矩阵分析与应用第2版>时,会发现总结了大量线性代数的知识,主要是给工科生用的.归纳了不少论文中的解法 ...

  6. 国行Android手机使用google全套GMS服务小结

        由于众所周知的原因,国行手机是不能内置google服务的,但作为铁杆google粉,没有GMS的Android不是完整的Android,NEXUS系列机器又由于各种原因买不到或者不想选购,那么 ...

  7. jQuery获取区间随机数

    1.自定义函数 function getRandom(min,max){    //x上限,y下限    var x = max;    var y = min;    if(x<y){     ...

  8. 洛谷 P3670 [USACO17OPEN]Bovine Genomics S奶牛基因组(银)

    P3670 [USACO17OPEN]Bovine Genomics S奶牛基因组(银) 题目描述 Farmer John owns NN cows with spots and NN cows wi ...

  9. 对string的一些扩展函数

    对string作了一些扩展,包含string转化为int.string转化为double.string转化为bool.打印系统当前时间.但没有解决数据溢出的问题,请大神帮忙解决! //头文件 /*pa ...

  10. IOS 以随意点为圆心 旋转UIView

    环绕底边中点旋转                     UIView本身是支持旋转的,能够用UIView.transform属性实现旋转. The origin of the transform i ...