Atomikos Forum

RollBack and insert into rollbacklogs table on RuntimeException


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>    
<!-- 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">
            <prop key="*">PROPAGATION_REQUIRED, -Exception</prop>

In service class
    public void doInTransaction(){
        System.out.println(" Calling t1Dao.updateT1()");
        System.out.println(" Calling t2Dao.updateT2()");

    public void doInsert(){
        System.out.println(" Calling t1Dao.doInsert()");
        System.out.println(" Calling t2Dao.doInsert()");
    public void doProcess(){
        System.out.println(" In doProcess ");        
            System.out.println(" Calling doTransaction ");    
        }catch(RuntimeException ex){
            System.out.println(" Calling doInsert ");
            System.out.println(" After doInsert ");            
Just Doit Send private email
Thursday, August 05, 2010
Did you try with PROPAGATION_NESTED to isolate the code you want to have the exception in?

Guy Pardon Send private email
Monday, August 09, 2010

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics