Hi everybody,first excuse me for my english,i'm from a speaking french country.
I use Spring and namedjdbctemplate pour my transaction,i can select,insert,update...
The problem is that when i have exceptions,the transaction is not rollbacked.This is my code.
spring-database.xml
HTML Code:
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="maDataSource">
<property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@monserveur:1521:MONDEV"/>
<property name="username" value="MABASE"/>
<property name="password" value="MABASE"/>
<property name="testOnBorrow" value="true"/>
<property name="validationQuery" value="SELECT 1 FROM DUAL"/>
<property name="maxActive" value="40"/>
<property name="maxIdle" value="20"/>
<property name="minIdle" value="5"/>
<property name="maxWait" value="60000"/>
<property name="timeBetweenEvictionRunsMillis" value="900000"/>
<property name="numTestsPerEvictionRun" value="5"/>
<property name="removeAbandoned" value="true"/>
<property name="removeAbandonedTimeout" value="30"/>
<property name="logAbandoned" value="true"/>
</bean>
spring-context.xml
HTML Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd" >
<context:annotation-config />
<bean class = "fr.sib.digor.spring.extension.AnnotationTransactionAttributeSourceReplacerPostProcessor" />
<bean id="maSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="maDataSource" />
<property name="configLocations">
<list>
<value>classpath*:hibernateSIPSDM.cfg.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="maSessionFactory" />
<qualifier value="txManager" />
</bean>
<tx:annotation-driven />
</beans>
spring-services.xml
HTML Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring
http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.0.xsd">
<bean id="namedJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
<constructor-arg ref="maDataSource"/>
</bean>
<aop:aspectj-autoproxy/>
</beans>
My service
PHP Code:
@Service
public class MonService {
@Autowired
protected MonDAO monDAO;
@Transactional(value="txManager", rollbackFor={Exception.class})
public void serviceAppelant(String param) throws Exception{
try {
monDAO.updateSex(param);
} catch (Exception up) {
throw up;
}
}
}
My DAO
PHP Code:
public class MonDAO {
@Autowired
private NamedParameterJdbcTemplate namedJdbcTemplate;
public void updateSex(String param){
try {
SqlParameterSource namedParameters = new MapSqlParameterSource(
"param", param);
namedJdbcTemplate.update(SQL_TEMPLATE_UPDATE, namedParameters);
//Baq query wich throw an exception
namedJdbcTemplate.update("BAD_QUERY", namedParameters);
} catch (Exception e) {
throw e;
}
}
}
My test method
PHP Code:
@Test
public void update() throws Exception{
monService.serviceAppelant("1289");
}
What did i miss?
Thank you.