How to add the mode=mysql to embedded H2 DB in Spring Boot 1.4.1 for @DataJpaTest?

前端 未结 5 2103
自闭症患者
自闭症患者 2020-12-18 20:41

I have some problems with using a schema.sql file to create my sql schema when executing a junit test while this schema contains mysql specific expression. I have to add the

5条回答
  •  独厮守ぢ
    2020-12-18 21:09

    I was able to run it with this config:

    # for integration tests use H2 in MySQL mode
    spring.datasource.url=jdbc:h2:mem:testdb;DATABASE_TO_LOWER=TRUE;MODE=MySQL;
    spring.jpa.database-platform=org.hibernate.dialect.MariaDBDialect
    

    The main trick here is to force Hibernate to generate SQL scripts for MariaDB dialect because otherwise Hibernate tries to use H2 dialect while H2 is already waiting for MySQL like commands.

    Also I tried to use more fresh MariaDB103Dialect for MariaDB 10.3 but it doesn't worked properly.

提交回复
热议问题