0
I am making an application with Spring Boot and using the H2 bank.
When I register a person, they get id 1, if I register someone else gets id 2 and so on, only if I restart the bank I lose everything and the first person I register has id 1 and so on, I wanted it to continue as id 3, 4.
Is there any way to save the data in the H2 database?
Man application.properties
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update
To use without being in memory you can opt for mariaDB Mysql or Postgresql, when data is saved in memory the intention is that they are not saved after the execution, however they can be used while your server/container is running.
– André Martins
The problem is that you specified
h2:
mem
:testdb
. That’s what’s keeping you in memory. Use the optionfile
withAUTO_RECONNECT=TRUE
- I had converted the answers to comment, but I had to reverse the process (they are answers, but they appear incorrect).– Bacco