Spring Business Focus

Source: Internet
Author: User
The three most important types of communication for spring transactions

First of all, this article only discusses the three kinds of transaction propagation, namely propagation_required,propagation_required_new,propagation_nested.

Background: When designing a business, it is impossible for all business operations to be done by themselves, put in a method, and sometimes need to call other methods, other colleagues ' code. In this case, we need to consider the propagation of the transaction.

A method transaction is required, and we are talking about what kind of transaction the B method call should take

  1. Propagation_required, the most commonly used transaction. Scenario: The business a method calls the B method. A is already REQUIRED affairs, B uses propagation_required, divides into two kinds of situation consideration, the first kind: a success or failure has no effect on B, the answer is yes, a method exception caused rollback operation will affect the operation result of the B method is invalid. The second type: B's success or failure on a has no effect. The answer is yes, an exception to the B method causes the rollback operation to affect the result of the A method's operation invalid. B and A are the most common logic for failure and success.
  2. Propagation_required_new, Scenario: Business A method calls the B method. A already is REQUIRED affairs, B uses Propagation_required_new, divides into two kind of situation consideration, the first kind: a success or failure has no effect on B, the answer needs to elaborate, a method occurrence exception causes the rollback operation to cause B not to call before B, A exception occurs after the B method has no effect on B. The second type: B's success or failure on a has no effect. The answer needs to be discussed in detail, and the exception of the B method causes the rollback operation A to capture the exception, which does not affect a. The exception of the B method causes the rollback operation A to not capture the exception, and A's operation is also rolled back.
  3. propagation_nested, Scenario: Business A method calls the B method. A already is REQUIRED affairs, B uses propagation_nested, divides into two kinds of circumstances to consider, with propagation_required_new situation. Special instructions, when the B method transaction commits the completion of the B method before including the operation of A to commit. When B rolls back only B itself rolls back without affecting the operation of a.

Spring Business Focus

Related Article

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.