正在学习声明式事务,搞不定了,没回滚,不知道为什么,求教public interface MyUserDAO { public void save(Myuser transientInstance);
}public class MyUser extends HibernateDaoSupport implements MyUserDAO {
private static final Log log = LogFactory.getLog(MyUser.class); protected void initDao() {
// do nothing
} public void save(Myuser transientInstance) {
log.debug("saving Myuser instance");
try {
log.debug("save successful");
getHibernateTemplate().save(transientInstance);
throw new RuntimeException(); //抛出异常,测试回滚
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}} <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<tx:advice id="txAdviceAddUser" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" />
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:advisor pointcut="execution(* com.zjm.study.dao.MyUserDAO.*.*(..))" advice-ref="txAdviceAddUser" />
</aop:config>

解决方案 »

  1.   

    应该是 com.zjm.study.dao.*.*(..) 吧~
      

  2.   

    后面的*.*(..)的意思是 任意类.任意方法(任意参数).你的MyUserDao是接口 第一个*号前面必须是个类
      

  3.   

    是配置的问题吧。如果你出现任何异常都要回滚,你最好加一个。<tx:method name="get*" read-only="false" rollback-for="Exception"/>
    这样,当出现异常时,就回滚了。
      

  4.   

    <tx:advice id="txAdviceAddUser" transaction-manager="transactionManager">
            <tx:attributes>
                <tx:method name="save*" propagation="REQUIRED"/>  //配置事务级别
                <tx:method name="*" read-only="true"/>
            </tx:attributes>
        </tx:advice>
        <aop:config>
              <aop:pointcut id="daoMethods" expression="execution(* com.zjm.study.dao.*.*(..))" /> //你的写错了 按照这样写
              <aop:advisor  advice-ref="txAdviceAddUser" pointcut-ref="daoMethods" /> 
        </aop:config>