浏览 1825 次
锁定老帖子 主题:请教下spring的事务管理问题
该帖已经被评为新手帖
|
|
---|---|
作者 | 正文 |
发表时间:2008-03-06
下面是在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> 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2008-03-06
你的异常被捕获了..
|
|
返回顶楼 | |
发表时间:2008-03-06
zdllionheart 写道 你的异常被捕获了..
改了下,以前是直接抛出的Exception,是不是抛出特定异常才会回滚? 我这样设过,还是没办法回滚,谢谢 <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,PROPAGATION_SUPPORTS,-Exception</prop> <prop key="modify*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="*">PROPAGATION_REQUIRED,PROPAGATION_SUPPORTS,-Exception,-ServletException,-UncategorizedSQLException</prop> </props> </property> </bean> |
|
返回顶楼 | |
发表时间:2008-03-06
汗.......
建议你好好看看spring的手顺.......... 3楼的写法是错的 最少那里的效果和你想要的效果是不一样的 1楼的对 只是下面那个bean那里定义的有问题 你没有把server声明成事务 |
|
返回顶楼 | |
发表时间:2008-03-06
ddandyy 写道 汗.......
建议你好好看看spring的手顺.......... 3楼的写法是错的 最少那里的效果和你想要的效果是不一样的 1楼的对 只是下面那个bean那里定义的有问题 你没有把server声明成事务 你的意思是 <bean id="simpleService" class="test.SimpleService"> <property name="dataSource" ref="dataSource" /> </bean> 这里没有声明么,但<property name="beanNames"> <list> <value>simpleService</value> </list> </property> 是不是已经把这个bean纳入到事务管理了?不对的话麻烦举个例子哈,谢谢! |
|
返回顶楼 | |