I am trying to dump data from H2 database to data.sql file in my project by executing such command:
SCRIPT TO '/home/mat/Projects/myapp/server/src/main/resources/data.sql'
Data is dumped and sql file is populated but when I am restarting app exception is thrown:
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "ADDRESS" already exists; SQL statement:
CREATE MEMORY TABLE "PUBLIC"."ADDRESS"( "ID" BIGINT DEFAULT (NEXT VALUE FOR "PUBLIC"."SYSTEM_SEQUENCE_D07A8597_940F_46CC_9CCA_78B64543126F") NOT NULL NULL_TO_DEFAULT SEQUENCE "PUBLIC"."SYSTEM_SEQUENCE_D07A8597_940F_46CC_9CCA_78B64543126F", "CITY" VARCHAR(255), "COUNTRY" VARCHAR(255), "HOME_NO" VARCHAR(255), "POSTAL_CODE" VARCHAR(255), "STREET" VARCHAR(255) ) [42101-199]
Why is it? Database and its data should be initialized on startup but looks like hmm? Entites from project are generated first and that is why exception is thrown?
My app.properties file:
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.enabled=true
spring.jpa.show-sql=true