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也能用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值