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

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. 用json2.js 代替 json.js防止与jQuery的js冲突

    用json2.js 代替 json.js防止与jQuery的js冲突 1 s.toJSONString json.js:259 2 Object.toJSONString json.js:158 3 ...

  2. Tensorlfow学习笔记----collection

    本文来源:http://blog.csdn.net/u012436149/article/details/53894354 tensorflow  之  collection tensorflow的c ...

  3. python note #3

    Hello, guys! I found it pretty difficult to get my content according to my key words. So in this not ...

  4. Ubuntu中的解压缩文件的方式

    记录Ubuntu下各种压缩和解压方式: .tar 解包:tar xvf FileName.tar 打包:tar cvf FileName.tar DirName (注:tar是打包,不是压缩!) -- ...

  5. 生成ssh公有密钥而且注冊到Github Generate ssh rsa keys and register public key on Github

    私有密钥和公有密钥是成对的两个文件,私有文件保存在自己的本机,公有密钥保存到还有一端的server,站点等. github就是一种站点. 仅仅有保存了私有密钥的机器才干訪问远程的server等. 使用 ...

  6. OpenCASCADE Face Normals

    OpenCASCADE Face Normals eryar@163.com Abstract. 要显示一个逼真的三维模型,其顶点坐标.顶点法向.纹理坐标这三个信息必不可少.本文主要介绍如何在Open ...

  7. amaze ui各个模块简单说明

    amaze ui各个模块简单说明 导航添加依据 http://amazeui.org/css/  下面内容属学习笔记,如有理解偏差和错误请留言相告,感谢!* =(官网这块写的很详细) 一.基本样式 1 ...

  8. 46.Express框架 GET 方法和POST 方法

    转自:http://www.runoob.com/nodejs/nodejs-express-framework.html GET 方法 以下实例演示了在表单中通过 GET 方法提交两个参数,我们可以 ...

  9. js -- canvas img 封装

    鼠标   1.操作canvas 中的 img. 右键放大缩小,左键移动img. 2.拖动input type= range  改变图片的透明度 html 代码 <!DOCTYPE html> ...

  10. C# 爬虫总结

    static void Main(string[] args) { //WebRequest request = WebRequest.Create("http://www.cnblogs. ...