Announcement Announcement Module
Collapse
No announcement yet.
Transaction Rollback issue in Spring-IBatis Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transaction Rollback issue in Spring-IBatis

    Hi,

    I am trying to do series of inserts in my Java application using Spring/iBatis.
    On exception, transaction rolls back successfully and none of inserts gets committed if i used the following settings in spring xml:

    <bean id="DerbyDBDataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver" />
    <property name="url" value="jdbc:derby://localhost:1527/C:/db-derby-10.6.2.1-bin/db-derby-10.6.2.1-bin/bin/TESTDB;" />
    <property name="initialSize" value="1" />
    <property name="maxActive" value="5" />
    <property name="maxIdle" value="5" />
    <property name="minIdle" value="1" />
    </bean>

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource" ref="DerbyDBDataSource"/>
    </bean>

    However if i use the following JNDI datasource settings instead of above datasource configuration, transaction NEVER rolls back. The insert statements always gets committed.

    <bean id="jndiDataSource"
    class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="resourceRef"><value>true</value></property>
    <property name="jndiName">
    <value>jdbc/TESTDB</value>
    </property>
    </bean>
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource" ref="jndiDataSource"/>
    </bean>

    My code structre is like this:
    public String insertAll(params){
    txManager = (PlatformTransactionManager) SpringHelper.instance().getBean("transactionManage r");
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("xyz");
    def.setPropagationBehavior(TransactionDefinition.P ROPAGATION_REQUIRED);
    // start a transaction
    TransactionStatus transactionStatus = txManager.getTransaction(def);
    try{
    insert1();
    insert2();
    insert3();
    }catch{
    txManager.rollback(transactionStatus);
    }

    Even though control goes to catch block above, whenver there is an exception, rollback method doesn't seem to have any effect. The data is still persisted in my derby database.


    I am using Websphere Application Server 6 + Spring 2.5 + iBatis + Derby 10.6.2.1 (Derby Network Server (XA) Provider that uses the Derby Client)

    Any pointers on why transactions are not getting rolled back when there are exceptions...(NullPointer/sqlexception etc..)? Is it because of Derby database 10.6.2 version OR PlatformTransactionManager or is it because AppServer transaction manager is overriding Spring transaction manager? I also read somewhere that WebsphereUOWTransactionManager can be used but using this transaction manager gives me error: "No JTA UserTransaction available - programmatic PlatformTransactionManager.getTransaction usage not supported".
    So i am forced to use NON-JNDI way of setting the datasource which is not recommended in my organization. Please help.
Working...
X