3

I have a moderate size project using Spring Boot, and I am trying to create my first DataJpaTest with embedded H2, but I am getting the following exception:

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "drop table project.project.driver if exists" via JDBC Statemen
Caused by: org.h2.jdbc.JdbcSQLException: Schema "PROJECT" not found; SQL statement:

I have tried this and using a schema.sql, also this and using a test.properties in test/resources, and this other answer. But nothing worked. I am really baffled; this is the first time I face an issue in Spring Boot that I am not able to figure it out.

My entity classes are defined as:

@Entity
@Table(name = "table_name", schema = "project", catalog = "project")
@Lombok.Data
public class TableNameEntity { }

Any suggestion of how to force Hibernate to create the schema in H2?

Rayniery
  • 1,557
  • 2
  • 12
  • 17

1 Answers1

1

You can pass a sql script which create schema in h2`s url:

jdbc:h2:mem:somedb;DB_CLOSE_DELAY=-1;INIT=RUNSCRIPT FROM 'classpath:create_schema.sql'

And in create_schema.sql would be something like this

CREATE SCHEMA IF NOT EXISTS project;
mzherdev
  • 462
  • 1
  • 4
  • 11
  • 1
    I already try using a schema.sql script as I mentioned on my question. The script got executed, but when I try to use a repository it threw the exception saying that there is not schema named like that. – Rayniery Mar 26 '19 at 22:02