0
votes

I started making a simple spring boot application.

My first step was to make use of Spring JDBC support, with default H2 in-memory database. For sample data, I had schema.sql and data.sql in src/main/resources.

So when spring launches, it also executes these 2 scripts and populate H2 database, which I can access via H2 console.

All works fine, and I can test correct data being returned by controllers.

Then I added JPA support by adding:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

But ever since, those 2 scripts(schema.sql, data.sql) are no more executed.

Does JPA dependency cause it? And what is the workaround to make it work?

1

1 Answers

1
votes

Since you are using spring-boot-starter-data-jpa you can set the following property in application.properties and it should work if you have hibernate and that is causing the problem (most probably):

spring.jpa.hibernate.ddl-auto = none

In a JPA-based app, you can choose to let Hibernate create the schema or use schema.sql, but you cannot do both. Make sure to disable spring.jpa.hibernate.ddl-auto if you use schema.sql.

The schema.sql is a spring based initialization process and having hibernate in classpath will conflict with this.So, you can try disabling hibernate auto config like this. Official doc.

If that it not the case please share entire pom file.