Spring documentation says, "a method within the target object calling another method of the target object, will not lead to an actual transaction at runtime even if the invoked method is marked with @Transactional."
One solution is to set "mode" in <tx:annotation-driven/> as aspectj, which will override the default mode proxy.
Another solution is make the methods public and invoke them directly from the upper layer,for the methods, which need to be in separate transaction.
For more details refer the spring docs.
static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html
In proxy mode (which is the default), only external method calls coming in through the proxy are intercepted. This means that self-invocation, in effect, a method within the target object calling another method of the target object, will not lead to an actual transaction at runtime even if the invoked method is marked with @Transactional.
Consider the use of AspectJ mode (see mode attribute in table below) if you expect self-invocations to be wrapped with transactions as well. In this case, there will not be a proxy in the first place; instead, the target class will be weaved (that is, its byte code will be modified) in order to turn @Transactional into runtime behavior on any kind of method.
No comments:
Post a Comment