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
- 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.
- 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.
- 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