A detailed explanation of spring transactions

Source: Internet
Author: User

1.spring Transaction principle: The essence of the spring transaction is that the database supports the transaction, and the function of the transaction cannot be provided without the support of the database to the transaction.

2.spring Transaction Propagation Properties:

Propagation_required supports the current transaction and creates a new transaction if there is no current transaction. This is the most common choice and is also the propagation of Spring's default transactions.
Propagation_requires_new a new transaction, suspending the current transaction if a transaction is currently present. The newly created transaction will have no relation to the suspended transaction, is two separate transactions, after the outer transaction fails rollback, cannot roll back the results of the inner transaction execution, the inner transaction fails to throw an exception, the outer transaction is caught, or the rollback operation can not be processed
Propagation_supports supports the current transaction and is executed in a non-transactional manner if no transaction is currently in use.
The propagation_mandatory supports the current transaction and throws an exception if there is no current transaction.
The propagation_not_supported executes the operation in a non-transactional manner, suspending the current transaction if a transaction is currently present.
The propagation_never is executed in a non-transactional manner and throws an exception if a transaction is currently present.
propagation_nested If an active transaction exists, it is run in a nested transaction. If there is no active transaction, it is performed by the required property. It uses a separate transaction that has multiple savepoint that can be rolled back. The rollback of internal transactions does not affect external transactions. It only works with the Datasourcetransactionmanager transaction manager.

3.spring Transaction ISOLATION Level:

Isolation_default This is a platfromtransactionmanager default isolation level, which uses the default transaction isolation level of the database. The other four correspond to the isolation level of JDBC.
Isolation_read_uncommitted This is the lowest isolation level of a transaction, which allows another transaction to see the uncommitted data for this transaction. This isolation level produces dirty reads, non-repeatable reads, and Phantom reads.
Isolation_read_committed guarantees that a transaction modified data is committed before it can be read by another transaction. Another transaction cannot read uncommitted data for the transaction.
Isolation_repeatable_read This transaction isolation level prevents dirty reads and cannot be read repeatedly. However, Phantom reads may occur.
Isolation_serializable This is the most cost-effective, but most reliable, transaction isolation level. Transactions are processed for sequential execution.

A detailed explanation of spring transactions

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.