Hi all
I have an outer bean IAstuteCallback which calls an inner bean IDataHandler (in a loop and I want each loop to commit or rollback).
If the inner bean IDataHandler throws a DataHandlerException then the transaction is rolled back and the data is not persisted to the database.Code:IAstuteCallback.saveData() { --> PROPAGATION_REQUIRED,-MyException1,-MyException2 IDataHandler.handleData() --> PROPAGATION_REQUIRES_NEW,-DataHandlerException,-Throwable }
But if the inner bean throws a Throwable (eg: org.springframework.dao.InvalidDataAccessApiUsageE xception - incorrect Hiberante usage) then the transaction is not rolled back and the data is persisted. Which is counter to what should happen so if someone could point out what I am doing wrong please?
The outer bean:
The inner bean:Code:<!-- The Astute Adapter transaction attributes bean --> <bean id="astute.adapter.transactionAttributeSource" class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource"> <property name="properties"> <props> <prop key="*"> PROPAGATION_REQUIRED,-MyException1,-MyException2 </prop> </props> </property> </bean> <!-- The Astute Adapter bean which has transactions for its method --> <bean id="agreement.astute.support.adapter" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="proxyInterfaces"> <list> <value>IAstuteAdapter</value> <value>IAstuteCallback</value> </list> </property> <property name="target"> <ref bean="agreement.astute.support.adapter.impl"/> </property> <property name="transactionManager"> <ref bean="support.transaction.manager"/> </property> <property name="transactionAttributeSource"> <ref bean="astute.adapter.transactionAttributeSource"/> </property> </bean>
I tried removing the outer transaction from the IAstuteCallback.saveData() method but then I get:Code:<!-- The transaction attributes bean --> <bean id="astute.transactionAttributeSource" class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource"> <property name="properties"> <props> <prop key="handleData"> PROPAGATION_REQUIRES_NEW,-DataHandlerException,-Throwable </prop> </props> </property> </bean> <!-- The IAstuteDataHandler bean which has transactions for its method --> <bean id="agreement.astute.data.handler" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="proxyInterfaces"> <list> <value>IAstuteDataHandler</value> </list> </property> <property name="target"> <ref bean="agreement.astute.data.handler.impl"/> </property> <property name="transactionManager"> <ref bean="support.transaction.manager"/> </property> <property name="transactionAttributeSource"> <ref bean="astute.transactionAttributeSource"/> </property> </bean>
.Code:org.springframework.transaction.NoTransactionException: No transaction aspect-managed TransactionStatus in scope
I am using Spring 2.0.5, Hibernate 3.1.1 and the code is being called from a JUnitTest.
Any suggestion would be appreciated!
Thanks Aisling


Reply With Quote