Search code examples
javaspringaopspring-transactions

@Transactional public method invokes private method


I have a service:

@Service
public class SImpl implements S {
    @Override
    @Transactional(readOnly = true)
    public void mPublic() {
       mPrivate();
    }


    private void mPrivate() {
        // some find method from database
    }
}

Is it works? I mean that it will do in transaction find method?


Solution

  • The transaction will start at the call to the mPublic method and end on the returning from it. It doesn't matter if local methods will be called inside of this methods. You can consider such methods the same way as code blocks inside of the method.

    If a runtime exception occurs somewhere inside the transaction it will be rolled back. Otherwise it will be committed.