急死人了<!-- 数据访问 -->
<bean id="test.sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="test.dataSource" />
<property name="configLocation" value="/WEB-INF/mybatis/mybatis-config.xml"></property>
</bean>

<bean id="test.sqlMapper" abstract="true" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="sqlSessionFactory" ref="test.sqlSessionFactory" />
</bean> <!-- 事务管理 -->
<bean id="test.transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
          <property name="dataSource" ref="test.dataSource"></property>
    </bean>
     
    <!-- 启用注解事务 -->
    <tx:annotation-driven transaction-manager="test.transactionManager"/>
使用@Transactional注解接口中的一个方法,然后在实现的方法里手动抛出一个runtime异常,发现根本不回滚,急死了要

解决方案 »

  1.   

    <bean id="test.transactionManager"> 中加:
            <property name="jpaDialect">
                <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
            </property>
      

  2.   

    public int DeleteRole(int roleId)
    {
    int result = sqlMapper.deleteRole(roleId);
    if(result>0)
    {
    sqlMapper.deleteRoleAction(roleId);
    sqlMapper.deleteUserRole(roleId);
    }
    throw new RuntimeException("测试回滚");
    //return result;
    }
      

  3.   

    启动就报错了,我用的是mybatis,没有hibernate
      

  4.   

    public int DeleteRole(int roleId)
    {
    int result = sqlMapper.deleteRole(roleId);
    if(result>0)
    {
    sqlMapper.deleteRoleAction(roleId);
    sqlMapper.deleteUserRole(roleId);
    }
    throw new RuntimeException("测试回滚");
    //return result;
    }
    我是说你的类有没写好注解啊之类的
      

  5.   

    public int DeleteRole(int roleId)
    {
    int result = sqlMapper.deleteRole(roleId);
    if(result>0)
    {
    sqlMapper.deleteRoleAction(roleId);
    sqlMapper.deleteUserRole(roleId);
    }
    throw new RuntimeException("测试回滚");
    //return result;
    }
    我是说你的类有没写好注解啊之类的
    我是新手,我听说只需要在接口写就可以了
    public interface Service 
    {
    @Transactional
    int DeleteRole(int roleId);
    }
    没有在xml里面做声明式事务,好麻烦,我还没搞懂
      

  6.   

    我刚刚遇到过这样的清空,
    用mysql建表默认不是innoDB,所以即使我程序里面是带事物的,也无效。
    后来把数据表结构改成了支持事物的innoDB就好了
      

  7.   

    在applicationContent.xml中声明事务
    <bean id="transactionManager"  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
             <property name="dataSource">  
                 <ref local="dataSource"></ref>  
             </property>  
         </bean>  
         
          <!-- 声明式事务管理 -->
        <bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
            <property name="transactionManager" ref="transactionManager"></property>
            <property name="transactionAttributes">
                <props>
                    <prop key="insert*">PROPAGATION_REQUIRED</prop>            
                    <prop key="update*">PROPAGATION_REQUIRED</prop>
                    <prop key="delete*">PROPAGATION_REQUIRED</prop>
                    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
                </props>
            </property>
        </bean>
    然后在需要事务的类前加上@Transactional
      

  8.   

    我的是mssql,已经解决了,@Transactional要加上事务名称
    比如<tx:annotation-driven transaction-manager="test.transactionManager"/>
    需要@Transactional("test.transactionManager")才能启用这个事务,无法做到多数据库事务,好像是不支持,不过感觉这个用处不大,因为跨数据库的事务管理很没有效率,估计没几个人用
      

  9.   

    很简单  你要明白spring对事物管理是怎么回事 你首先要确定配置的正确性 然后对事物的控制