undefinedfix
Sign in

Spring, mysql, no @ Is there a dirty read problem with select in transactional methods?

CMPND edited in Thu, 07 Jul 2022

In spring, under the default RR isolation level of MySQL, there is no transaction support for select in the method without @ transactional, right? So is there a dirty reading problem?

2 Replies
SpenserWilson1
commented on Thu, 07 Jul 2022

No, dirty reads only appear at the lowest isolation level Ru

user282
commented on Thu, 07 Jul 2022

Actually, it has nothing to do with spring, but the essence is mysql.

We should also distinguish the relationship between transaction and isolation level. When there are concurrent transactions, if there is no proper isolation boundary, the concurrency state will be incorrect. In short, different isolation levels are the trade-off and compromise between ensuring the correct system state and performance.

Moreover, if the data engine of MySQL is InnoDB. In InnoDB database engine, all database statements executed by users occur in transactions. If autocommit mode is started, each SQL statement starts a separate transaction by itself. By default, MySQL starts session at each connection, and autocommit is on by default. Therefore, if this SQL statement is executed and no error is returned, MySQL automatically executes commit. Of course, you can close it manually. Spring has done a lot for you.

Finally, repeatable reading is the default transaction isolation level for MySQL.

No matter how spring is coded, it also gives the database function construction. It is recommended that you take a look at the MySQL document, which is very informative.