The transaction guarantees integrity by inserting three tables simultaneously. The following is a simple test:
1. Locking the table
Lock User Table
LOCK TABLES user WRITE;
To see if a table is locked:
OPEN where > 0;
Displays the table that is locked.
2. Verify that the operation can be inserted under the same session
Insert into User Values (10002,'127.0.0.1',7,'pc');
Can be manipulated successfully.
3. Start the Spring app and perform the insert operation, not successful.
4, Unlocking
UNLOCK TABLES;
To view a locked table:
OPEN where > 0;
The above table is not locked.
5. Call the Spring app, perform the insert operation, and the operation can succeed.
Therefore, it is OK to apply Spring's @transactional for transaction management.
Appendix:
SHOW OPEN TABLES syntax:https://dev.mysql.com/doc/refman/5.0/en/show-open-tables.html
db_name] [like ' pattern ] expr
SHOW OPEN TABLESLists the non- TEMPORARY tables that is currently open in the table cache. Seesection 8.4.3.1, "How MySQL Opens and closes Tables". The WHERE clause can is given to select rows using more general conditions, as discussed on section 19.18, "Extensions to SHOW statements ".
The and clauses may used as of FROM LIKE 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 db_name in the database.
SHOW OPEN TABLESOutput 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 is For the table. For example, if one client acquires a lock for a table Using lock table T1 WRITE , < Code class= "literal" >in_use will be 1. If another client Issues lock table T1 WRITE while The table remains locked, the CL Ient would block waiting for the lock, but the lock request Causes in_use to is 2. If The Count is zero, the table was open but not currently being Used. in_use is als o Increased by The handler ... OPEN statement 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 tests whether spring transactions are in effect