zoukankan      html  css  js  c++  java
  • spring boot 事务的一些实践


    起先:


    @Service
    @Transactional

    class xxxService


            indMsgDao.batchRead(userId);
    
            List<IndMsg> list = indMsgDao.findByUserId(userId, pageable);
            Integer total = indMsgDao.countByUserId(userId);
    
            int a = 1 / 0;

        @Query("update IndMsg e set e.is_read = '1' where e.user_id = :user_id ")
        @Modifying
        Integer batchRead(@Param("user_id") Integer user_id);


    这段代码抛出异常,但没有执行回滚

    比较奇怪的是:


            indMsgDao.batchRead(userId);
    
            int a = 1 / 0;
    
            List<IndMsg> list = indMsgDao.findByUserId(userId, pageable);
            Integer total = indMsgDao.countByUserId(userId);


    这段代码可以回滚,找了半天没找到,最终,查到是mysql引擎没有选择innerdb,汗


    参考了这个帖子:http://www.cnblogs.com/youzhibing/p/6127250.html


    不同的是,我这边jdbctemplate是可以回滚的


    顺便提一下,spring boot 事务配置

    添加@EnableTransactionManagement注解,该注解启用了注解式事务管理 <tx:annotation-driven />,这样在方法上的@Transactional注解就起作用了,但是实际测试中不加这句,@Transactional注解依然有用


    http://www.cnblogs.com/java-zhao/p/5350106.html

    我试了下,即使没有@EnableTransactionManagement也能用

  • 相关阅读:
    HTTP协议
    django-两种方式对单表的操作
    模态框对话
    django
    web框架原理
    DNS详解
    jQuery
    初识web框架
    练习:简单主页搭建
    多表查询
  • 原文地址:https://www.cnblogs.com/silyvin/p/9106801.html
Copyright © 2011-2022 走看看