Hi,
I'm observing some strange transaction behaviour and cannot for the life of me figure out what I'm doing wrong.
I've two methods, methodOne and methodTwo. Both have transaction attributes and methodTwo calls methodOne. It appears that the attributes on methodOne are ignored in this situation. Calling methodOne on its own appears fine.
Looking at the log traces there is a call,
DEBUG [org.springframework.transaction.interceptor.Transa ctionInterceptor] - Getting transaction for method 'methodTwo' in class [test.TransactionTestI]
but this never happens for methodOne, even though as I mentioned, methodOne is called by methodTwo.
Here is an application context from a very simple test situation I set up. In reality, I'm using source code annotations but see the same behaviour.
with the transactionManager being a HibernateTransactionManager, although this basic test does not access Hibernate.Code:<bean id="transactionTestTarget" class="test.TransactionTest" /> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager"><ref bean="transactionManager"/></property> <property name="transactionAttributeSource"> <value> test.TransactionTestI.methodOne=PROPAGATION_NEVER test.TransactionTestI.methodTwo=PROPAGATION_REQUIRED </value> </property> </bean> <bean id="transactionTest" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="proxyInterfaces"> <value>test.TransactionTestI</value> </property> <property name="target"><ref local="transactionTestTarget"/></property> <property name="interceptorNames"> <list> <value>transactionInterceptor</value> </list> </property> </bean>
The behaviour I'd expect in the above case of attributes is that an exception would be thrown when calling methodOne due to the PROPAGATION_NEVER. It isn't thrown.
Has anyone any ideas what maybe causing this problem, or am I wrong in my assumption about the behaviour of one transactioned method calling another?
Here's a log trace with pertinant logging turned on:
Code:INFO [org.springframework.orm.hibernate.LocalSessionFactoryBean] - Building new Hibernate SessionFactory INFO [org.springframework.orm.hibernate.HibernateTransactionManager] - Using DataSource [org.apache.commons.dbcp.BasicDataSource@f6f1b6] from Hibernate SessionFactory for HibernateTransactionManager DEBUG [org.springframework.transaction.interceptor.MethodMapTransactionAttributeSource] - Adding transactional method [test.TransactionTestI.methodTwo] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT] INFO [org.springframework.transaction.interceptor.MethodMapTransactionAttributeSource] - Adding transactional method [public abstract void test.TransactionTestI.methodTwo()] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT] DEBUG [org.springframework.transaction.interceptor.MethodMapTransactionAttributeSource] - Adding transactional method [test.TransactionTestI.methodOne] with attribute [PROPAGATION_NEVER,ISOLATION_DEFAULT] INFO [org.springframework.transaction.interceptor.MethodMapTransactionAttributeSource] - Adding transactional method [public abstract void test.TransactionTestI.methodOne()] with attribute [PROPAGATION_NEVER,ISOLATION_DEFAULT] DEBUG [org.springframework.transaction.interceptor.TransactionInterceptor] - Getting transaction for method 'methodTwo' in class [test.TransactionTestI] DEBUG [org.springframework.orm.hibernate.HibernateTransactionManager] - Using transaction object [org.springframework.orm.hibernate.HibernateTransactionObject@1582a7c] DEBUG [org.springframework.orm.hibernate.HibernateTransactionManager] - Creating new transaction DEBUG [org.springframework.orm.hibernate.SessionFactoryUtils] - Opening Hibernate session DEBUG [org.springframework.orm.hibernate.HibernateTransactionManager] - Opened new session [net.sf.hibernate.impl.SessionImpl@a010ba] for Hibernate transaction DEBUG [org.springframework.orm.hibernate.HibernateTransactionManager] - Beginning Hibernate transaction on session [net.sf.hibernate.impl.SessionImpl@a010ba] DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] - Bound value [org.springframework.orm.hibernate.SessionHolder@149f041] for key [net.sf.hibernate.impl.SessionFactoryImpl@29d294] to thread [main] DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] - Bound value [org.springframework.jdbc.datasource.ConnectionHolder@1984a9d] for key [org.apache.commons.dbcp.BasicDataSource@f6f1b6] to thread [main] DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] - Initializing transaction synchronization DEBUG [test.TransactionTest] - In method two DEBUG [test.TransactionTest] - In method one DEBUG [org.springframework.transaction.interceptor.TransactionInterceptor] - Invoking commit for transaction on method 'methodTwo' in class [test.TransactionTestI] DEBUG [org.springframework.orm.hibernate.HibernateTransactionManager] - Triggering beforeCommit synchronization DEBUG [org.springframework.orm.hibernate.HibernateTransactionManager] - Triggering beforeCompletion synchronization INFO [org.springframework.orm.hibernate.HibernateTransactionManager] - Initiating transaction commit DEBUG [org.springframework.orm.hibernate.HibernateTransactionManager] - Committing Hibernate transaction on session [net.sf.hibernate.impl.SessionImpl@a010ba] DEBUG [org.springframework.orm.hibernate.HibernateTransactionManager] - Triggering afterCompletion synchronization DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] - Clearing transaction synchronization DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] - Removed value [org.springframework.jdbc.datasource.ConnectionHolder@1984a9d] for key [org.apache.commons.dbcp.BasicDataSource@f6f1b6] from thread [main] DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] - Removed value [org.springframework.orm.hibernate.SessionHolder@149f041] for key [net.sf.hibernate.impl.SessionFactoryImpl@29d294] from thread [main] DEBUG [org.springframework.orm.hibernate.HibernateTransactionManager] - Closing Hibernate session [net.sf.hibernate.impl.SessionImpl@a010ba] after transaction DEBUG [org.springframework.orm.hibernate.SessionFactoryUtils] - Closing Hibernate session
thanks
Jonny


Reply With Quote