spring2.0+Struts2.0+hibernate+SQL2000现在遇到问题了 事务不回滚 service.impl代码如下我抛出异常为Exceptionpublic TAccountUser updateUserTeleNumber(String accountCard,String newTeleNumber,String chargeType)throws Exception{
//更新主叫号码
operList.setActchgGiveAmount(0.0);
operList.setActchgAmount((double)(chargeList.getTochargeAmount()));
//添加用户动态金额信息
super.getModelDaoFactory().getAccountRegModelDaoFactory().getAccountRegInfoDao().saveAccountOperList(operList);   ///这段代码是添加语句 调试断点走到这里后这段话已经执行了数据库数据也被添加了。我纳闷了
//故意抛出异常
Integer.parseInt("ss");
更新用户金额信息
super.getModelDaoFactory().getAccountRegModelDaoFactory().getAccountRegInfoDao().updateUserTeleNumber(user);
}事务的配置如下<!-- 配置sessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:plugins-sp/hibernate-sp.cfg.xml">
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean> <!-- 配置事务的传播特性 此为advice ,把这个advice 圈定到pointcut所指向的方法-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="destory*" propagation="REQUIRED" />
<tx:method name="drop*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="create*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />
<tx:method name="serch*" propagation="REQUIRED" />
<!-- 只读,不需要更新,所以减少了步骤,优化 -->
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice> <!-- 那些类的哪些方法参与事务 -->
<aop:config>
<!-- * 有无返回值都可,圈定xxx.xxx.*.*包下面所有的类所有的方法(..)任意参数 -->
<aop:pointcut id="allManagerMethod"
expression="execution(* com.hongxun.sp.service.account.*.*(..))" />
<!-- advisor相当于aspect其中包含了 pointcut,和advice -->
<aop:advisor pointcut-ref="allManagerMethod"
advice-ref="txAdvice" />
</aop:config>
 為什麼断点走到添加哪里数据库已经添加了,而且走到异常哪里也没有回滚。检查了N边都没找到错。我怀疑是SQL2000的问题。hibernate里面设置的自动提交为 true 请大家帮忙看下。 

解决方案 »

  1.   

    事物回滚需要抛throw new RuntimeException("");  不然事物不会回滚.
      

  2.   

    Note that this also means that auto-commit after every single SQL statement is useless in an application, this mode is intended for ad-hoc SQL console work. Hibernate disables, or expects the application server to do so, auto-commit mode immediately
      

  3.   

    hibernate文档
    11.1.1. Unit of work 
      

  4.   

    抛出RuntimeException或者捕获RuntimeException异常都可以了!
      

  5.   

    <aop:pointcut id="allManagerMethod"
    expression="execution(* com.hongxun.sp.service.account.*.*(..))" />这个出现问题了