1

I have this H2 url on my application.properties:

spring.datasource.url=jdbc:h2:mem:myschema;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS myschema;MV_STORE=FALSE;MVCC=FALSE
spring.datasource.driver-class-name=org.h2.Driver
spring.h2.console.enabled=true
spring.h2.console.path=/db
spring.h2.console.settings.trace=true
spring.h2.console.settings.web-allow-others=true
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect

But when my app starts I have these logs.

2018-03-09 02:48:12.745 DEBUG 7248 --- [  restartedMain] o.s.j.d.DriverManagerDataSource          : Creating new JDBC DriverManager Connection to [jdbc:h2:mem:myschema;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS myschema;MV_STORE=FALSE;MVCC=FALSE]
2018-03-09 02:48:12.828  WARN 7248 --- [  restartedMain] o.h.e.j.e.i.JdbcEnvironmentInitiator     : HHH000342: Could not obtain connection to query metadata : Schema "myschema" not found [90079-196]
2018-03-09 02:48:12.835  INFO 7248 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2018-03-09 02:48:12.855  INFO 7248 --- [  restartedMain] o.h.e.j.e.i.LobCreatorBuilderImpl        : HHH000422: Disabling contextual LOB creation as connection was null
2018

It seems like H2 is closed just after the connexion and as you can see on the URL, it should not. I use Liquibase to create my tables on that schema and as the database is closed, it raised this exception :

Caused by: liquibase.exception.DatabaseException: org.h2.jdbc.JdbcSQLException: Schema "myschema" not found [90079-196]
    at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:390) ~[liquibase-core-3.5.5.jar:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1769) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1706) ~[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    ... 21 common frames omitted
Caused by: org.h2.jdbc.JdbcSQLException: Schema "myschema" not found [90079-196]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:345) ~[h2-1.4.196.jar:1.4.196]
    at org.h2.message.DbException.get(DbException.java:179) ~[h2-1.4.196.jar:1.4.196]
    at org.h2.message.DbException.get(DbException.java:155) ~[h2-1.4.196.jar:1.4.196]
    at org.h2.engine.Database.getSchema(Database.java:1755) ~[h2-1.4.196.jar:1.4.196]
    at org.h2.engine.Session.setCurrentSchemaName(Session.java:1265) ~[h2-1.4.196.jar:1.4.196]
    at org.h2.jdbc.JdbcConnection.setSchema(JdbcConnection.java:1928) ~[h2-1.4.196.jar:1.4.196]
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:210) ~[spring-jdbc-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:169) ~[spring-jdbc-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:385) ~[liquibase-core-3.5.5.jar:na]
    ... 23 common frames omitted

I am using Spring Boot 2 which manages Hibernate (5.2.14.Final) and H2 (1.4.196).

Thanks for your help

akuma8
  • 4,160
  • 5
  • 46
  • 82
  • Checkout this answer by H2 author Thomas Müller: https://stackoverflow.com/a/5228564/332248 Maybe you just need double backslashes in your `INIT`(before the `;`) – Jens Mar 12 '18 at 18:00
  • @Jens Does not work. – akuma8 Mar 12 '18 at 18:53

0 Answers0