玩辅助的上单 2019-07-09 10:22 采纳率: 0%
浏览 474

update不会事务回滚求问大佬们是哪的问题?

# 用spring boot做数据导出时,插入数据抛异常可以事务回滚,但是update却不会事务回滚求问大佬们是哪的问题?

启动类


@SpringBootApplication(scanBasePackages = {"com.moredata"})


@MapperScan({"com.moredata.dao","com.moredata.dao.master"})

@ComponentScan(basePackages = "com.moredata.*")

@EnableTransactionManagement

@EnableAspectJAutoProxy

@EnableScheduling

public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Bean
    public PlatformTransactionManager txManager(DataSource dataSource){
        return new DataSourceTransactionManager(dataSource);
    }

    @Bean
    public Object testBean(PlatformTransactionManager platformTransactionManager){
        System.out.println(">>>>>>>>>>"+platformTransactionManager.getClass().getName());
        return new Object();
    }
}

mapper不会回滚方法



public interface EmGrZsmxSyncDtoMapper {

    @Update({
            "update EM_GR_ZSMX_SYNC",
            "set SYNC_STATE = '1'",
            "where ID = #{id,jdbcType=DECIMAL}"})
    void updateSyncStateById(BigDecimal id);
}

service



@Service

@Transactional(rollbackFor=Exception.class)

public class TestOneServiceImp implements ITestOneService {

@Resource
    TestOneDtoMapper testOneDtoMapper;

    @Resource
    TestTwoDtoMapper testTwoDtoMapper;

    @Resource
    OperationLogDtoMapper operationLogDtoMapper;

    @Resource
    EmGrZsmxSyncDtoMapper emGrZsmxSyncDtoMapper;

    @Resource
    ImpDataDtoMapper impDataDtoMapper;

    @Resource
    EmGrZsmxSyngLogDtoMapper emGrZsmxSyngLogDtoMapper;
@Override

    @Log(methodDesc = "数据导出")

    @Transactional(rollbackFor=Exception.class)
    public void insertEM(EmGrZsmxSyncDto emGrZsmxSyncDto) {

            System.out.println("定时插入进入");
            impDataDtoMapper.insert(emGrZsmxSyncDto);
            emGrZsmxSyncDtoMapper.updateSyncStateById(emGrZsmxSyncDto.getId());
            EmGrZsmxSyngLogDto emGrZsmxSyngLogDto = new EmGrZsmxSyngLogDto();
            emGrZsmxSyngLogDto.setSyncId(emGrZsmxSyncDto.getId());
            emGrZsmxSyngLogDto.setZzbh(emGrZsmxSyncDto.getZzbh());
            emGrZsmxSyngLogDto.setSyncDate(new Date());
            JSONObject jsonObject = JSONObject.fromObject(emGrZsmxSyncDto);
            String jsonStr = jsonObject.toString();
            emGrZsmxSyngLogDto.setSyncContent(jsonStr);
            emGrZsmxSyngLogDtoMapper.insert(emGrZsmxSyngLogDto);
            System.out.println(emGrZsmxSyncDto.getId());
            throw new RuntimeException("运行异常");

    }


}
  • 写回答

2条回答 默认 最新

  • 真-酸辣土豆丝 2019-07-09 11:22
    关注

    回滚要有异常产生。你的update有产生异常吗?

    评论

报告相同问题?

悬赏问题

  • ¥20 怎么在stm32门禁成品上增加记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 解riccati方程组