Do Spring transaction annotations of multiple methods in the same class belong to the same transaction?

is the transaction in which multiple methods in the same class call annotations to each other the same

wrote a method with a lot of rows, and there are a lot of operations on the database, and now you want to propose these operations as separate methods. Do you want to annotate these separate releases? do they still call the same transaction after they are annotated?

related codes

public class Word{
    @Transaction
    public void A(){
        String b = this.B();
        return this.C(b);
    }
    
    @Transaction
    public String B(){
        // do something
    }

    @Transaction
    public String C(String b){
        // do something
    }
}

found this article yesterday
spring transaction propagation behavior example analysis

May.05,2022

in theory, the nesting of multiple things follows the constraint of spring transaction propagation attribute, that is to say, it may or may not be in the same transaction (based on the propagation attribute you set), but you here are internal calls, B and C calls do not leave the agent transaction invalid, so you are still in the same transaction.

clipboard.png

Menu