1

For example we have bean service which has two methods and one of them (testA) execute another one (testB).

public class TestServiceImpl implements TestService {
...
public void testA() throws Exception {
    ...     
    try {
        this.testB();
    catch(Exception e)
    {
        ...
    }
    ...
}
public void testB() throws Exception {
    ...
}

}

Method testB is defined with PROPAGATION_REQUIRES_NEW transaction attribute, method testA is defined with PROPAGATION_REQUIRED.

<bean id="TestService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="target" ref="TestServiceTarget"/>
    <property name="transactionManager" ref="transactionManager"/>
    <property name="transactionAttributes">
        <props>             
            <prop key="testB*">PROPAGATION_REQUIRES_NEW, ISOLATION_READ_COMMITTED, -Exception</prop>
            <prop key="*">PROPAGATION_REQUIRED, ISOLATION_READ_COMMITTED, -Exception</prop>
        </props>
    </property>
</bean>

Then we execute testA method of this service. In logs we can see then for method testA new transaction is created, what is OK. But when testB method is executed from methodA, in logs we have information that actual transaction is being used instead of suspending actual and creating another one (like is defined in configuration).

So is it normal behaviour in spring that when we execute service method in other method of the same service, spring omit transactional configuration for this method (like in example for method testB) and always use PROPAGATION_REQUIRED attribute?

Additionally let's say when method testB is from other service and configuration for this method is the same (PROPAGATION_REQUIRES_NEW) everything seems tobe fine (new transation is created, actual suspended).

As transaction manager is used WebSphereTransactionManagerFactoryBean (spring 2.5).

thanks

doctoor
  • 11
  • 2

1 Answers1

1

Yes, it's a normal behaviour.

See 7.6.1 Understanding AOP proxies for explanation and some workarounds. Also see Spring - @Transactional - What happens in background?.

Community
  • 1
  • 1
axtavt
  • 239,438
  • 41
  • 511
  • 482
  • 1
    Well, maybe it's not normal, but this is a well known Spring transactions issue: http://nurkiewicz.blogspot.com/2009/08/spring-aop-riddle.html, http://nurkiewicz.blogspot.com/2009/09/spring-aop-riddle-demystified.html – Tomasz Nurkiewicz Feb 09 '11 at 11:59