alibaba / druid

阿里云计算平台DataWorks(https://help.aliyun.com/document_detail/137663.html) 团队出品,为监控而生的数据库连接池
https://github.com/alibaba/druid/wiki
Apache License 2.0
27.92k stars 8.57k forks source link

spring.datasource.druid.default-auto-commit=false #3198

Open xu-xiwei opened 5 years ago

xu-xiwei commented 5 years ago

spring.datasource.druid.default-auto-commit=false 项目用springboot+mybatis 想把事务自动提交关闭,service不开启事务,insert还是能插入。这个有什么用呢

superleo-cn commented 5 years ago

我也遇到类似问题 @Transactional加上类似readOnly=truepropagation = Propagation.SUPPORTS,虽然不创建Spring事务,但是提交的时候由于 MySQL 默认的autocommit导致数据还是入库。

你查看一下源码,其实根本没有这个属性。另外MySQL官方也提到了,autocommit是默认开启的。

In InnoDB, all user activity occurs inside a transaction. If autocommit mode is enabled, each SQL statement forms a single transaction on its own. By default, MySQL starts the session for each new connection with autocommit enabled ...

如果你实在想要操作, 建议在MySQL的配置文件做类似如下设置:

init_connect='set autocommit=0'

这样连接上的客户端默认都是关闭的