Hi,
I'm trying to rollback transactions using spring declarative transaction management with iBatis.
I have set up a "facade" bean, which accesses a DAO (paysService).
In this DAO, I wrote a simple function : insertupdate, which is supposed to update an attribute of a record
AND to make an insert violating the Primary Key. This should raise a DataAccessException.
I should normally see no change in my database (oracle 8i), since both orders are in the same transaction and I set the -Exception flag on the "insert*" property.
Nevertheless, my changes are committed. I also tried with -DataAccessException, still no better.
When I test with a simple "java application" (see code below), my update is committed!
When I test with org.springframework.test package (JUnit test), transactions are rolled back OK, which is normal, according to the test package spec.
I seem to have a configuration problem, but I can't find where (I've seen several topics in the data access forum, and I tried to use all the solutions provided... without any luck).
Can anyone help me ?
Thanks,
JF.
XML Spring Configuration :
DAO function :Code:<beans> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>/com/kiabi/config/jdbc.properties</value> </list> </property> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName"><value>${jdbc.driverClassName}</value></property> <property name="url"><value>${jdbc.url}</value></property> <property name="username"><value>${jdbc.username}</value></property> <property name="password"><value>${jdbc.password}</value></property> </bean> <bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true"> <property name="transactionManager"><ref bean="transactionManager"/></property> <property name="transactionAttributes"> <props> <prop key="insert*">PROPAGATION_REQUIRED,-Exception</prop> <prop key="update*">PROPAGATION_REQUIRED,-Exception</prop> <prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop> <prop key="*">PROPAGATION_REQUIRED,readOnly</prop> </props> </property> </bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource"><ref local="dataSource"/></property> </bean> <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <property name="configLocation"><value>/com/kiabi/config/sqlmap_config.xml</value></property> </bean> <bean id="facade" parent="baseTransactionProxy"> <property name="target"> <bean class="com.kiabi.entreprise.impl.facadeImpl"> <property name="paysService"><ref bean="paysService"/></property> </bean> </property> </bean> <bean id="paysService" class="com.kiabi.entreprise.impl.PaysServiceImpl"> <property name="dataSource"><ref bean="dataSource"/></property> <property name="sqlMapClient"><ref bean="sqlMapClient"/></property> </bean> </beans>
Java Application Test function :Code:public boolean insertupdate(String strCodePays) throws DataAccessException { KPays p=new KPays(); p.setCodePays(strCodePays); KPays pays=this.getPays(p); pays.setLibPays("TEST"); getSqlMapClientTemplate().update("updateKPays",pays) ; getSqlMapClientTemplate().insert("insertKPays",pays) ; return true; }
Spring JUnit Test function :Code:ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( new String[] { "/com/kiabi/config/environnementTest.xml", "/com/kiabi/config/dataSource.xml", "/com/kiabi/config/services.xml" }); BeanFactory factory = (BeanFactory) appContext; facade ml= (facade)factory.getBean("facade"); PaysService kp=(PaysService) ml.getPaysService(); try { kp.insertupdate("FR"); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }
Code:public void testInsertUpdate() { ps=(PaysService)this.getFacade().getPaysService(); try { ps.insertupdate("FR"); } catch (DataAccessException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } assertNotNull("not exists", ps); } }


!
Reply With Quote