The confusion of Spring Mybaties affairs! Solve! !           


      
SUPPORTS declares that the business method does not require a transaction. If the business method is already in a transaction, the transaction is suspended. After the method is executed, the transaction is resumed; therefore, no matter whether your method will throw an exception, it will not There is a transaction operation, that is, your update operation on the database will not take effect, because there is no transaction, naturally there will be no transaction commit, as for the rollback, it is even more difficult to talk about.
    
Has invited:

qVkQgCtdv

Favor from:


      When customerName is equal to AAAA, you will throw an exception directly in your If statement block.
The following code will not go, the update method does not go, where do you come from the transaction? Where is the rollback?
    

PQzRfsaje

Favor from:


      Your transaction manager should be assigned to the service layer. This saves the two methods using the same transaction. It must be either a colleague's success or a failure at the same time.
    

age

Favor from:


      [size=x-small][color=red] Let me save you[/color][/size]

First of all, you need to post the scope of the things you define. If such a key thing is not posted, others can help you analyze it. I am really surprised.

Suppose your scope is defined like this. (assuming the definition is above your CustomerService class)

That is, your add method is already a proxy method. SPRING will put the transaction context into the current thread, and then enter your add method. Then all the operations on the database are a connection, so no matter where This method throws an exception in the above place will definitely roll
    

lOHVJbNMsu

Favor from:


      First of all, you have to understand that the transaction REQUIRED is added when there is a transaction. If you do not create a new one, you save and update in the same transaction, so they all roll back.
To achieve the effect you want (save ROLLBACK, update COMMIT), open the transaction, assign update to REQUIRES_NEW, and put it in 2 services.
    

To reply to a question, please Login or registered