Spring (iii)-transaction management

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.