복붙노트

[SPRING] 트랜잭션에서 롤백 없음 - Spring Boot 2.0

SPRING

트랜잭션에서 롤백 없음 - Spring Boot 2.0

스프링 부트 2.0.0에 문제가 있습니다. RuntimeException을 던지면 트랜잭션을 롤백하지 않습니다. 나는 스프링 부트 1.5.9를 동일한 설정으로 사용하고 있었고 효과가 있었다. 방금 Spring Boot 2로 마이그레이션하여 작동을 멈췄습니다.

내 구성 클래스 :

@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");
    }

}

아무도 무슨 일이 일어나고 있는지 알고 있습니까?

해결법

  1. ==============================

    1.어떤 방언을 사용하고 있습니까? spring.jpa.properties.hibernate.dialect를 지정해야합니다.

    어떤 방언을 사용하고 있습니까? spring.jpa.properties.hibernate.dialect를 지정해야합니다.

    Springboot 2.0 @Transaction은 org.hibernate.dialect.MySQL5Dialect에 의해 지원되지 않는다.

    오히려 org.hibernate.dialect.MySQL5InnoDBDialect를 사용하라.

  2. from https://stackoverflow.com/questions/49470187/no-rollback-on-transaction-spring-boot-2-0 by cc-by-sa and MIT license