Spring 启动@Transactional 不回滚
Spring boot @Transactional doesn't rollback
我正在使用 Spring 启动应用程序,我正在尝试实现事务管理。但是Spring不会回滚用相同方法保存的数据。
代码库:https://github.com/vinothr/spring-boot-transactional-example
谁能帮帮我?
这是我 'Test' 实体的存储库 class。
@Repository
public interface TestRepository extends CrudRepository<com.example.demo.Test, Long> {
}
我创建了一个用于将数据保存到 'Test' 实体的端点。保存发生后,我抛出 RunTimeException,但它没有回滚保存的值
@GetMapping("/test")
@Transactional
public void create() {
System.out.println("test");
final Test p = createTest();
testRepository.save(p);
final Test p1 = createTest();
testRepository.save(p1);
throw new RuntimeException();
}
尝试指出@Transactional(rollbackFor = RuntimeException.class)
我换成 'InnoDB' 引擎后工作正常,因为我使用的 'MyISAM' 引擎不支持事务。
ALTER TABLE my_table ENGINE = InnoDB;
我正在使用 Spring 启动应用程序,我正在尝试实现事务管理。但是Spring不会回滚用相同方法保存的数据。
代码库:https://github.com/vinothr/spring-boot-transactional-example
谁能帮帮我?
这是我 'Test' 实体的存储库 class。
@Repository
public interface TestRepository extends CrudRepository<com.example.demo.Test, Long> {
}
我创建了一个用于将数据保存到 'Test' 实体的端点。保存发生后,我抛出 RunTimeException,但它没有回滚保存的值
@GetMapping("/test")
@Transactional
public void create() {
System.out.println("test");
final Test p = createTest();
testRepository.save(p);
final Test p1 = createTest();
testRepository.save(p1);
throw new RuntimeException();
}
尝试指出@Transactional(rollbackFor = RuntimeException.class)
我换成 'InnoDB' 引擎后工作正常,因为我使用的 'MyISAM' 引擎不支持事务。
ALTER TABLE my_table ENGINE = InnoDB;