刚使用SPRING,在程序中使用了事务管理。
下面是在SimpleService里调用的addError()方法,在2出产生的异常并没用回滚1处的数据,希望各位指导下哪里出了问题,谢谢
public void addError() throws Exception {
SimpleDao dao = new SimpleDao(getDataSource());
dao.addRightInfo();//1---插入正确记录
dao.addErrorInfo();//2---插入错误记录
PS:在dao中使用的是NamedParameterJdbcTemplate类操作数据,是否数据已经提交无法再回滚了?
下面是主要的配置
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean name="transactionInterceptorBeanGroup"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="modify*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>simpleService</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptorBeanGroup</value>
</list>
</property>
</bean>
<bean id="simpleService" class="test.SimpleService">
<property name="dataSource" ref="dataSource" />
</bean>
下面是在SimpleService里调用的addError()方法,在2出产生的异常并没用回滚1处的数据,希望各位指导下哪里出了问题,谢谢
public void addError() throws Exception {
SimpleDao dao = new SimpleDao(getDataSource());
dao.addRightInfo();//1---插入正确记录
dao.addErrorInfo();//2---插入错误记录
PS:在dao中使用的是NamedParameterJdbcTemplate类操作数据,是否数据已经提交无法再回滚了?
下面是主要的配置
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean name="transactionInterceptorBeanGroup"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="modify*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>simpleService</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptorBeanGroup</value>
</list>
</property>
</bean>
<bean id="simpleService" class="test.SimpleService">
<property name="dataSource" ref="dataSource" />
</bean>