I'm trying to persist an H2 in-memory DB to a file with Spring Boot to reuse the data in there.
Unfortunately, the way to specify the datasource url like
spring.datasource.url = jdbc:h2:file:~/WeatherDB;FILE_LOCK=FS
(complete application.properties)
doesn't work for me. I can't find a file generated by H2 anywhere on my hard disk (also, saved data is not available after restarting the server).
To visualize this, I created a sample project that can be found on Bitbucket.
With that, it doesn't seem to make a difference if the application is run from an IDE with gradle run
or after packaging it from the jar.
What config option is needed to persist and reuse the H2 DB ?
Update:
I realized there is a actuator endpoint for config options at http://localhost:8080/configprops
that shows
"spring.datasource.CONFIGURATION_PROPERTIES": {
"prefix": "spring.datasource",
"properties": {
"schema": null,
"data": null,
"xa": {
"dataSourceClassName": null,
"properties": { }
},
"separator": ";",
"url": "jdbc:h2:file:~/WeatherDB",
"platform": "all",
"continueOnError": false,
"jndiName": null,
"sqlScriptEncoding": null,
"password": "******",
"driverClassName": "org.h2.Driver",
"initialize": true,
"username": "sa"
}
},
But I just can't find an file WeatherDB
on my harddisk nor is any data available after restarting the server.
Any suggestions very much welcome ;-)
Table get dropped due to schema migration setting it to update solved for me.
application.properties
spring.jpa.hibernate.ddl-auto=update
Your application.properties
file is not being picked up. Replace
compile "org.springframework.data:spring-data-jpa:1.7.2.RELEASE"
compile "org.hibernate:hibernate-entitymanager:4.3.8.Final"
with
compile "org.springframework.boot:spring-boot-starter-data-jpa"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With