2 abc123maxiaolong abc123maxiaolong 于 2013.11.01 17:13 提问

spring @Transactional 事务不能回滚

在spring的配置文件里配置如下:

<!-- enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven transaction-manager="txManager"/>

<!-- a PlatformTransactionManager is still required -->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <!-- (this dependency is defined somewhere else) -->
    <property name="dataSource" ref="dataSource"/>
</bean>

测试代码如下:

    @Override
@Transactional(propagation = Propagation.REQUIRED)
public void saveLoginInfo(String userName, String dateString, String result) {
    String sql = "INSERT INTO prc_mbl_usr_usg (slsprs_id, lgn_dtm, lgn_sts ) VALUES (" + "'" + userName + "'," + "'" + dateString + "'," + "'" + result + "')";
    logger.info(sql);
    toolsDao.insertUtils(sql);
    int m = 1;
    if (m == 1) {
        throw new RuntimeException();
    }
    toolsDao.insertUtils(sql);
}

抛出异常后,异常前面的insert插入的记录无法回滚,求解

1个回答

zuohao821221
zuohao821221   2013.11.08 10:19

回滚后,是又插入了吧。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!