Issue
AFAIK
In proxy mode (which is the default), only 'external' method calls coming in through the proxy will be intercepted. This means that 'self-invocation', i.e. a method within the target object calling some other method of the target object, won't lead to an actual transaction at runtime even if the invoked method is marked with @Transactional!
But here is: Transactional.TxType.REQUIRES_NEW
Will be the second transaction created?
@Service
public class SomeService {
@Transactional
public void doSomeLogic() {
// some logic
doOtherThings();
// some logic
}
@Transactional(Transactional.TxType.REQUIRES_NEW)
private void doOtherThings() {
// some logic
}
Solution
To get an answer to this question, you need to know how a proxy works.
When you annotate a method inside a bean, the proxy will wrap that bean with the appropriate logic. This means that if you call that annotated method of your bean, the request will first be sent to the proxy object (named with $), which will then call the bean's method. If this method calls another method of the same bean, it will call it without invoking a proxy which has a logic, e.x., of transaction management.
Example: Here is the code which will be wrapped by proxy and an appropriate diagram of its work.
@Service
public class SomeService {
@Transactional
public void foo() {
// this next method invocation is a direct call on the 'this' reference
bar();
}
@Transactional(Transactional.TxType.REQUIRES_NEW)
public void bar() {
// some logic...
}
}
Hence, the answer is No.
Hope that's a little bit more clear now.
Answered By - Valery