1,spring has two ways of managing transactions: ① programmatic ② declarative. Programming is more flexible, but the code is large, there are more duplicate code, and declarative transaction management is more flexible and convenient than programming.
The declarative transaction management based on AOP is essentially intercepting the method before and after execution, and then creating and joining the transaction before the method executes, committing the transaction according to execution or rolling back the transaction after executing the target method.
There are two forms of declarative transaction management: The ① configuration file ② add @transaction annotations to the business method and apply the transaction rules to the business logic.
2,spring's transaction management interface has three main: Transactiondefinition, Platform TransactionManager, Transaction Status.
① in spring, transactions are defined by the Transactiondefinition interface, which contains methods related to transaction properties, Transactiondefinition defines five constants representing isolation levels, constants that represent propagation behavior, In Transactiondefinition, the time-out is expressed as an int value.
The ②platform transactionmanager.getinstance () method returns a transaction status object that returns the transaction The status object may represent a new or already existing transaction (if there is a qualifying transaction in the current call stack).
The ③transaction status interface provides a simple way to control transaction queries and execution.
Another: Whether a transaction needs to be created is controlled by the transactional propagation behavior. Read data does not need or specify a read-only transaction, and the transaction is required to change the transaction management.