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个回答

回滚后,是又插入了吧。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问