Atomikos Forum |
|
Hi,
I have a requirement wherein am inserting some data into my db and some point of time i am throwing RuntimeException on a particular condition. When the RuntimeException is thrown i need to rollback the transaction along with this i need to insert some other data into my logs table. I am using Spring with atomikos. There is a handler configured in my app-context.xml which wraps transactions around my service class which calls the Dao methods. If a RuntimeException occurs the transaction is getting rolledback but how to insert data into some other table?? If i catch the RuntimeException and in the catch block if i do the insert?? If RuntimeException is thrown i need to catch it somewhere if i catch the transaction is not rolling back Please guide me... <bean id="tService" class= "test.T1ServiceImpl"> <property name="t1Dao"><ref bean="t1Dao" /></property> <property name="t2Dao"><ref bean="t2Dao" /></property> </bean> <!-- Configure Spring to insert JTA transaction logic for all methods --> <bean id="t1Service" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager"><ref bean="springTransactionManager" /></property> <property name="target"><ref bean="tService" /></property> <property name="transactionAttributes"> <props> <prop key="*">PROPAGATION_REQUIRED, -Exception</prop> </props> </property> </bean> In service class public void doInTransaction(){ System.out.println(" Calling t1Dao.updateT1()"); t1Dao.updateT1(); System.out.println(" Calling t2Dao.updateT2()"); t2Dao.updateT2(); } public void doInsert(){ System.out.println(" Calling t1Dao.doInsert()"); t1Dao.doInsert(); System.out.println(" Calling t2Dao.doInsert()"); t2Dao.doInsert(); } public void doProcess(){ System.out.println(" In doProcess "); try{ System.out.println(" Calling doTransaction "); doInTransaction(); }catch(RuntimeException ex){ ex.printStackTrace(); System.out.println(" Calling doInsert "); doLog(); System.out.println(" After doInsert "); } } |