Sobes.tech
Junior — Senior

Number of transactions during an internal method call in a Spring bean

livecode

Task condition

In the Spring bean MyService, the method a() is annotated with @Transactional, and method b() directly calls a(). At the same time, b() is called through an injected bean. How many transactions will be opened as a result of this call and why?

@Component
public class MyService {

    @Transactional
    public void a() {
        // somecode
    }

    public void b() {
        // somecode
        a();
    }
}