Reputation: 139
I am quite new to Spring and JPA environment. I wrote small code that stores information of Offices by using repository.save(Office object)
operation. But when I rerun the code it shows that there is no such entry (that I entered before). How can I permanently store information in a database using JPA?
Upvotes: 0
Views: 259
Reputation: 2576
If you only use h2 without any configuration (only dependency in gradle/maven), then spring will create inmemory db for you. To change this setting you can create your own DataSource
Bean. Also there is a simpler way if you use spring boot - just configure it in application.properties
.
spring.datasource.url=jdbc:h2:file:<path to to store url>;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update
Upvotes: 1