1

I am trying to create a simple SpringDataJPA application. I am using H2 database. After annotating the model class with @entity annotation the table is successfully created in H2 DB and the same can be viewed through the h2-console. however to initialise the table i am trying to insert the values from data.sql but while starting the application the error indicates that the table is not being found . Why is the table not being found when I am able to view the ?

POM.xml

Model Class

application.properties

data.sql

Console output

maveric123
  • 13
  • 4
  • please dont post links - post actual code. Anyways this might answer your question: https://stackoverflow.com/questions/67678311/spring-boot-is-not-creating-tables-automatically – J Asgarov May 26 '21 at 12:48

1 Answers1

5

Spring Boot 2.5.0 changed the way schema.sql and data.sql are handled.

You have to set

spring.jpa.defer-datasource-initialization=true

to make your example work.

Please read https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto.data-initialization.using-basic-sql-scripts

Simon Martinelli
  • 34,053
  • 5
  • 48
  • 82