【spring + hibernate】 事物无法回滚问题

【spring + hibernate】 事物无法回滚问题

问题描述:

事物配置:
Java代码

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">   
   <property name="sessionFactory">   
    <ref bean="sessionFactory"/>   
   </property>   
</bean>   

<!--事物的传播特性  -->   
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">   
   <tx:attributes>   
        <tx:method name="save*"   />   
        <tx:method name="*" read-only="true"  />   
       </tx:attributes>   
    </tx:advice>   
<aop:config>   
  <aop:pointcut id="transactionOperation" expression="execution(* com.base.service..*.*(..))" />   
  <aop:advisor  advice-ref="transactionAdvice" pointcut-ref="transactionOperation" />   
</aop:config>  
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
   <property name="sessionFactory">
    <ref bean="sessionFactory"/>
   </property>
</bean>

<!--事物的传播特性  -->
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
   <tx:attributes>
        <tx:method name="save*"   />
        <tx:method name="*" read-only="true"  />
       </tx:attributes>
    </tx:advice>
<aop:config>
  <aop:pointcut id="transactionOperation" expression="execution(* com.base.service..*.*(..))" />
  <aop:advisor  advice-ref="transactionAdvice" pointcut-ref="transactionOperation" />
</aop:config>

Java代码
server 层为事物边界

public void saveGame(GameClassEntity o) {

this.GameDao.saveGame(o);

}

server 层为事物边界

public void saveGame(GameClassEntity o) {
this.GameDao.saveGame(o);
}

Dao 层的方法 不管你抛什么异常 打死也不回滚! 极度郁闷ing

Java代码
public void saveGame(GameClassEntity o){

this.save(o);

throw new RuntimeException("测试异常");

}

public void saveGame(GameClassEntity o){
    this.save(o);
         throw new RuntimeException("测试异常");
}

希望路过者指点一二!!!

[quote]您的
没有定义事务异常,改成
当抛出此异常回滚。[/quote]

不对! spring 默认 RuntimeException 会回滚的 :wink:

您的
没有定义事务异常,改成
当抛出此异常回滚。