Issue
I am using Spring Boot 2.1.3 with an H2 in memory database for testing. When I run my tests, the schema gets generated even when I specify the following property.
spring.jpa.generate-ddl=false
It seems that because Spring Boot defaults the following property when using H2
spring.jpa.hibernate.ddl-auto=create-drop
That this takes precedence over spring.jpa.generate-ddl=false
Is this a bug?
Solution
This behavior is described in the Spring Boot Features documentation in chapter 11.3.3. Creating and Dropping JPA Databases:
By default, the DDL execution (or validation) is deferred until the
ApplicationContext
has started. There is also aspring.jpa.generate-ddl
flag, but it is not used if Hibernate auto-configuration is active, because theddl-auto
settings are more fine-grained.
Since the property spring.jpa.hibernate.ddl-auto
is set by default if Hibernate is used, the flag spring.jpa.generate-ddl
is ignored if Hibernate is used (at least with a H2 in-memory database)
Answered By - Dominik