Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the considerations for spring transactions

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

What are the considerations of spring transactions? in view of this problem, this article introduces the corresponding analysis and solutions in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

Transaction generally refers to database transaction, which refers to a series of operations executed as a program execution unit, either completely or not at all. A transaction is a result-oriented standard of judgment.

Features of spring (ACID)

(1)。 Atomicity (atomicity)

Atomicity is an indivisible unit of work. To put it simply, it means that all the operations contained in the transaction are either successful or all failed rollback. Therefore, if the operation of the transaction is successful, it must be fully applied to the database, and if it fails, it cannot have any impact on the database.

(2)。 Consistency (consistency)

Consistency means that a transaction must change one consistency state into another, that is, a library must be in a consistency state before and after execution. In terms of money transfer, suppose user An and user B add up to 5000. So no matter how much money is transferred between An and B and how many times it is transferred, the total money of the two is still 5000 after the end of the transaction.

(3)。 Isolation (isolation)

Isolation means that the execution of one transaction cannot be interfered with by another. When multiple users access the database concurrently and operate the same table, the transactions opened by the database for each user can not be disturbed by the operations of other transactions, and the concurrent transactions should be isolated from each other.

(4)。 Persistence (durability)

Persistence means that once a transaction is committed, the change to the database data is permanent. Even if the data system encounters a failure, the operation of committing the transaction is not lost.

Isolation level of spring

* dirty reading: one transaction reads uncommitted data from another transaction

* cannot be read repeatedly: one transaction reads data that has been committed by another transaction (update), resulting in inconsistent results of multiple queries

* Unreal reading: one transaction reads data that has been committed by another transaction (insert), resulting in inconsistent results of multiple queries.

The default isolation level for sqlserver and oracle is RC,mysql, and the default isolation level is RR.

Considerations for spring

1. Exception cannot be rolled back, but only if RuntimeException and Error exceptions are thrown. two。 An exception is caught in the transaction code and cannot be rolled back.

3. If you are using spring+mvc mode. And both spring and mvc scan the service layer (transaction layer) and the transaction does not take effect. Because spring will load the configuration file of mvc limited, and the configuration of transactions is basically in spring, because the child container of spring starts before the parent container, the transaction has not been loaded when service is injected into controller.

4.mysql 's myISAM engine, which does not support transactions, needs to be set to innoDB mode.

5. The opening of the transaction must be loaded in the listener. If it is placed in the configuration of the dispatchServlet, the transaction will not take effect.

6. If you use @ Transactional in an interface, only JDK dynamic proxies will take effect, and CGLIB dynamic proxies will not take effect because annotations cannot be inherited.

The answers to the questions about spring affairs are shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report