Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If I restart the Rest server, H2 database reset

Tags:

spring

jpa

jdbc

h2

I used file db as below:

spring.datasource.url=jdbc:h2:file:./data/meet

And I can find file "meet.mv.db" in my working directory.

If I add tuples to the file and restart the server, the size of the file increases. However, I cannot get what is inside the file after restarting. That means there is no persistency at all.

Can anyone help me to find how to obtain persistency?

In case you need my source code: https://github.com/jihunim/meet_n_eat_server

like image 681
John Avatar asked Apr 15 '17 03:04

John


2 Answers

In application.properties:

spring.jpa.hibernate.ddl-auto=update

(from https://docs.spring.io/spring-data/jpa/docs/1.4.3.RELEASE/reference/html/jpa.repositories.html)

like image 198
Thomas Decaux Avatar answered Nov 13 '22 16:11

Thomas Decaux


I ran into a similar problem and I discovered it was because I had this property set in the persistence.xml file:

<property name="hibernate.hbm2ddl.auto" value="create-drop" />

Removing this line fixed the issue and data was still there after server restart.

like image 22
Pyrox Avatar answered Nov 13 '22 14:11

Pyrox