The use of Spring transactions in different classes

In the same service, if the externally called method A has a transaction, all methods in method A will use the transaction of method A, and the transaction of the sub-method is invalid

In a different service, if the externally called method A has a transaction, all methods in method A will use the transaction of method A by default, and if B has a transaction, B will use the transaction of B

Conclusion: If there is a transaction in method A called externally, all methods in method A will use the transaction of method A, and the sub-method transactions of the same type will fail, and the different types of sub-method transactions will take effect. After the new operation is rolled back, the Id value has been increased and will not be rolled back

  • The external method has @Transactional, and the internal method does not use the external method @Transactional
  • The external methods are not @Transactional, and the internal methods are not all separate transactions to create and submit themselves
  • External methods have @Transactional, internal methods also have internal methods that are not the same class @Transactional takes effect (determined by proxy principle)
  • External methods do not have @Transactional, internal methods have internal methods @Transactional take effect

Guess you like

Origin blog.csdn.net/qq_43621091/article/details/107070861