版权声明:作者已开启版权声明,如转载请注明转载地址。 https://blog.csdn.net/qq_34829447/article/details/82762985
学习SpringBoot的道路还是比较顺畅的,但是不乏会有些版本更新导致一些注解和操作的迭代更新,博主偶然间碰到了@Transactional注解无效的情况,查阅资料得到以下解决方案,分享给大家~
1.问题的出现
- 在SpringBoot使用jpa操作数据库,@Transactional注解无效,无法完成事务管理操作。
2.问题的分析
- Springboot2.0后,使用jpa操作数据库,发现默认创建表是myisam引擎,而不是innodb,myisam不支持使用@Transactional注解
3.问题的解决
- 通过application.yml将引擎设置为innodb类型(不加database-platform值则默认为myisam引擎)
spring:
profiles:
active: run
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/dbgirl
username: root
password: 123456
jpa:
hibernate:
ddl-auto: create
show-sql: true
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect