-
Notifications
You must be signed in to change notification settings - Fork 41.5k
Description
I'm trying to insert some rows in my entities for testing on developer machine using H2
Database. I'm using data.sql
for this.
It works fine, entities are created and then data.sql
is run to insert data in the tables produced by the entities.
However I need to create some other tables for which there are no entity classes, so I'm using schema.sql
for those. Here's the issue, as soon as I add schema.sql
to the project, Spring Boot runs data.sql
before creating entities, which ends in Table not found exception
.
It works fine if I replace data.sql
with import.sql
, it's run after the entities are created.
However h2
configuration is supposed to run only when testing, for that I have a maven profile which activates a spring.datasource.platform = h2
, to load schema-h2.sql
and data-h2.sql
. import.sql
doesn't work with the platform.
So the issue is that data.sql
is being run before entities are created only when schema.sql
is present.
Here's the Github repository for reproducing the issue
Without any platform
https://github.com/ConsciousObserver/SpringBootSchemaSqlIssue.git
With h2 platform (It's another branch platform-h2
in the above repository)
https://github.com/ConsciousObserver/SpringBootSchemaSqlIssue/tree/platform-h2
Stackoverflow
Thanks