ibates和sping的事务问题
applicationContext.xml 文件
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource">
<ref local="dataSource"/>
</property>
<property name="configLocation">
<value>classpath:SqlMapConfig.xml</value>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED,-RemoteException</prop>
<prop key="update*">PROPAGATION_REQUIRED,-RemoteException</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<value>*Service,*Dao</value>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
<bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
<property name="transactionInterceptor" ref="transactionInterceptor"/>
</bean>
action
public String insertInfo()throws Exception {
if (this.userService.checkName(userInfo.getUserName())) {
this.addActionError("该用户名已经存在,请重新输入");
this.userInfo.setUserName("");
return "add";
} else {
this.userService.insertUserInfo(userInfo);
this.organManageService.insertOrganInfo(organInfo);
return "listpage";
}
}
第二个添加语句是错误,但是事务没有回滚,第一条语句还是添加到了数据库中。
第一次配置事务,不知道该怎么解决??
------解决方案--------------------
只会另一种管理 事务 的方法。。
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<!-- 事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="up*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>