spring hibernate .. H2 database - schema not found

I found the mistake. it was the connection URL.

I changed the connection URL to the following

<property name="url" value="jdbc:h2:~/test;DB_CLOSE_DELAY=-1" />

referred the documentation at this location

http://www.h2database.com/html/features.html#database_url


Because you've have a schema name mismatch in your configuration.

This

<property name="url" value="jdbc:h2:mem:test;DB_CLOSE_DELAY=-1" />

And this

<prop key="hibernate.default_schema">DOCTORASSIST</prop>

have a conflict.

You're jdbc URL says that your working with test while your hibernate.default_schema is DOCTORASSIST, make sure both values are same.


The accepted answer was not fixed my problem, the working solution is to set the default schema as mentioned by Coder

<prop key="hibernate.default_schema">DOCTORASSIST</prop>

And also to initialize the creation of the schema:

<property name="hibernate.connection.url" value="jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS DOCTORASSIST"/>

As mentioned by user2180794 the parameter test is the name of the database and not the name of the schema


Upvoted accepted answer.

In my case the problem was executing @DataJpaTest: the initial statement to drop tables failed with error "schema not found".

Just want to share Spring Boot application.yml (in my case under test/resources):

spring:
  jpa:
    database: h2
    show-sql: true
    hibernate:
      ddl-auto: create-drop
    properties:
      hibernate:
        default_schema: metering
        connection:
          url: jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS my-schema-name
      username: sa
      password: