Spring Boot + JPA:@Transactional 注释:回滚不起作用

Nav*_*lla 3 java spring jpa spring-boot

我正在将 @Transactional 与 spring boot 和 jpa 一起使用。但它不起作用。有人可以帮忙吗。

我的插入在 myDAO 中,它在服务类中自动装配。下面的代码是实现服务接口的服务类的方法

class MyService implements Service {

@Transactional(rollbackFor = RuntimeException.class)
    public ResponseVO createOrder(params) {
    myDAO.insertInTable1(param);
    myDAO.insertInTable2(param);//I kept wrong table name in this query such that it throws exception
         }

 }
Run Code Online (Sandbox Code Playgroud)

Nav*_*lla 6

问题在于 MySQL 数据库引擎。我的引擎是不支持事务的 MYIsam。我将我的数据库引擎更改为 InnoDB 及其工作。感谢您的贡献。以下是相同的查询。

SELECT ENGINE FROM information_schema.TABLES WHERE TABLE_NAME = 'tab_name' AND TABLE_SCHEMA='db_name';

ALTER TABLE table_name ENGINE = INNODB;