I have a Jhipster monolithic application. I removed Liquibase and I want to use data.sql file to insert initial data. I created a data.sql and data-h2.sql which contain insert scripts. They are located under src/main/resources
. But none of the data seems to be inserted.
How can I use data.sql to insert data during startup, without using Liquibase?
Commenting
spring.datasource.type
property and addingspring.jpa.hibernate.create-drop
property helped resolve this issue. I think some jhipster configuration overrides default spring-boot configuration.Here is how I come up with this solution:
While debugging
DataSourceInitializedPublisher.publishEventIfRequired
, I saw that following line returned anull
reference:I commented
spring.datasource.type
property inapplication-dev.yml
. In this way, spring switched to tomcat connection pool automatically.Then, I found out that
DataSourceInitializedPublisher.isInitializingDatabase
requiredspring.jpa.hibernate.hbm2ddl.auto
property to be defined in configuration:After adding the missing property, spring-boot started to execute
data.sql
file.Update
For those who want to execute a platform specific
data.sql
file, such asdata-h2.sql
, you should also add following property:Update
For those who need to convert default Jhipster data stored in csv files into sql format, you may refer to following gist:
https://gist.github.com/hkarakose/cf7f1b5b241dad611ba01c0211f42108