I have MySQL with tables in two databases and want to write a test with SpringBoot (1.5.6.RELEASE) and JPA. For this, I use the @DataJpaTest
together with @EntityScan
, as the entities are in two different packages. As embedded database for the test, I use H2.
- My first problem was, that Spring Boot threw an exception that the schemas were not found, therefore I created a
schema.sql
with twoCREATE SCHEMA IF NOT EXISTS
statements like described in this question. - However, I also wanted to insert some test data and added a
data.sql
file. The problem was now, that Spring boot first executed theschema.sql
, then thedata.sql
and following this Hibernate again created the tables, which eventually resulted in empty tables. To solve this problem, I tried to setspring.jpa.hibernate.ddl-auto=none
within theapplication.properties
. However, Hibernate now started to switch naming strategies and converted camelCase to sneak_case, which again resulted in errors. So I guess, this is not the way how it should be done. I also triedspring.jpa.generate-ddl=false
, but this did not have any effect.
How is it possible to deactivate the automatic DDL generation (only use schema.sql
and data.sql
) and at the same time use @DataJpaTest
?
Thank you very much!