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.sqlwith twoCREATE SCHEMA IF NOT EXISTSstatements like described in this question. - However, I also wanted to insert some test data and added a
data.sqlfile. The problem was now, that Spring boot first executed theschema.sql, then thedata.sqland 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=nonewithin 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!