交易无回滚-Spring Boot 2.0 [英] No rollback on transaction - Spring Boot 2.0
问题描述
我对Spring Boot 2.0.0有问题.当我抛出RuntimeException时,它不会回滚事务.我使用具有相同设置的Spring Boot 1.5.9,它可以正常工作.它只是迁移到Spring Boot 2并停止工作.
I have a problem with Spring Boot 2.0.0. When I throw an RuntimeException it is not rollback the transaction. I was using Spring Boot 1.5.9 with the same settings and it worked. It just migrated to Spring Boot 2 and stopped working.
我的配置类:
@Configuration
@EnableJpaRepositories(basePackages = "com.test.repository")
@EnableTransactionManagement
public class DatabaseConfiguration {
public static final String MODEL_PACKAGE = "com.test.model";
@Value("${jdbc.url}")
private String url;
@Value("${jdbc.username}")
private String username;
@Value("${jdbc.password}")
private String password;
@Bean
public DataSource dataSource() throws SQLException {
org.apache.tomcat.jdbc.pool.DataSource dataSource = new org.apache.tomcat.jdbc.pool.DataSource();
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
dataSource.setUrl(this.url);
dataSource.setUsername(this.username);
dataSource.setPassword(this.password);
return dataSource;
}
@Bean
public PlatformTransactionManager transactionManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
}
我的商务舱:
@Service
public class TestBusinessImpl implements TestBusiness {
@Override
@Transactional
public void save(final Test test) {
this.testRepository.save(test);
throw new RuntimeException("Test rollback");
}
}
有人知道会发生什么吗?
Does anyone know what may be happening?
推荐答案
您正在使用哪种方言?您必须指定spring.jpa.properties.hibernate.dialect
Which dialect are you using? You must be specifying spring.jpa.properties.hibernate.dialect
org.hibernate.dialect.MySQL5Dialect不支持Springboot 2.0 @Transaction
Springboot 2.0 @Transaction doesn't get supported by org.hibernate.dialect.MySQL5Dialect
而是使用org.hibernate.dialect.MySQL5InnoDBDialect
Rather use org.hibernate.dialect.MySQL5InnoDBDialect
这篇关于交易无回滚-Spring Boot 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!