Skip to content

Why spring-boot-starter-data-jpa 2.5.0 can not init data by the cause “table not found”?

I have 2 projects using the same H2 configurations:

    platform: h2
    url: jdbc:h2:mem:db;INIT=CREATE SCHEMA IF NOT EXISTS aso_security_db;SET SCHEMA aso_security_db;
    driverClassName: org.h2.Driver
    username: sa
    password: sa
    initialize: true
    data: classpath:sql/aso_security_db_init_data.sql

The first project used spring-boot-starter-data-jpa 1.5.8.RELEASE which can init data successfully. But the second one used spring-boot-starter-data-jpa 2.5.0 CAN NOT init data:

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "TBL_USER" not found; SQL statement:
INSERT INTO tbl_user ...

Trace the log I have seen that the init data sql is run before the db structure generated. Spring team! Please help to fix this issue to save time for many Spring members around the world!



In Spring Boot 2.5.0 you have to configure in your properties spring.jpa.defer-datasource-initialization=true. With this configuration, DataSource initialization will be able to build the schema performed by Hibernate. You can read more about this change here.

10 People found this is helpful