A detailed explanation of the propagation properties of transactions in spring

Source: Internet
Author: User

When we use spring, we use his declarative transactions very often, simply make some rule configurations in the configuration file, and take advantage of Spring's AOP capabilities to easily handle transactional problems; Here is a question about the propagation properties of a transaction "propagation", He defined in the Transactiondefinition interface, interested to see SRC, there are 7 options available:

Propagation_required: Supports the current transaction, and creates a new transaction if there are currently no transactions. This is the most common choice.

Propagation_supports: Supports the current transaction and executes it in a non transactional manner if there are currently no transactions.

Propagation_mandatory: Supports the current transaction and throws an exception if there are currently no transactions.

Propagation_requires_new: Creates a new transaction, suspends the current transaction if there is currently a transaction.

Propagation_not_supported: Performs an operation in a non transactional manner and suspends the current transaction if there is currently a transaction.

Propagation_never: Executes in a non transactional manner and throws an exception if there is a current transaction.

Propagation_nested: Supports current transaction, adds new savepoint point, commits or rolls back synchronously with current transaction.

Now with an example, apply the above various propagation properties to illustrate: First, declare two bean:servicea and SERVICEB, wherein SERVICEB is referenced;

view plaincopy to clipboardprint?
   ServiceA {
     void methodA() {
       ServiceB.methodB();
     }
   }

   ServiceB {
     void methodB() {
       // ...
     }
   }
   ServiceA {
     void methodA() {
       ServiceB.methodB();
     }
   }

   ServiceB {
     void methodB() {
      // ...
     }
   }

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.