1. Spring Transaction Management
Transaction management: The essence is to use spring to manage transactions and to complete database support for transactions.
Transactions: A collection of database operations, an operation error, all must be rolled back, which is characterized by acid.
(1 There is a problem with transaction concurrency:
Dirty read: Invalid transaction read data. The transaction T1 modifies a value, and then the transaction T2 reads the value, and thereafter T1 revokes the change to that value for some reason.
Non-repeatable READ: Two identical queries within a transaction range return different data. caused by the commit of other transaction modifications in the system at query time. Focus on modifying the same data.
Phantom read: Multiple transactional operations Unified data set. On the same terms, the number of records read out 1th and 2nd is different due to changes in transaction T2. Focus on adding and removing data sets.
Missing update: The transaction T2 operation overrides the transaction T1 operation.
(2 ) Spring Transaction Management Methods
Programmatic transaction management (programmatic transaction management using Transactiontemplate or directly using the underlying Platformtransactionmanager) allows for fine-grained granularity of code block transactions.
Declarative transaction management: Based on AOP, the essence is to intercept the method before and after it, and then create or join a transaction before the target method starts, committing or rolling back the transaction according to execution after the target method is executed. It is not necessary to doping transaction-managed code in business logic code.
(Includes two methods: XML configuration file based on TX and AOP namespaces/@transactional annotations, DAO layer annotations)
@Transactional (propagation=propagation.not_supported) public class Mybatisserviceimpl implements Mybatisservice { @Autowired Private Mybatisdao DAO; @Override public void Insert (test test) { Dao.insert (test); The thing propagation behavior is propagation_not_supported, operates in a non-transactional way, does not deposit the database Throws a unchecked exception, triggers a thing, rolls back throw new RuntimeException ("test"); } |
(3 ) Transaction ISOLATION Level
The degree of isolation between several concurrent transactions.
(4 ) Transaction propagation behavior
A transaction context already exists before the current transaction is started, and there are several options to specify the execution of a transactional method.
Spring (iii)-transaction management