Search code examples
javahibernatejpahsqldb

Create schema before hbm2ddl


I want to test my program with an inmemory hsqldb. To create the table I use hibernate.hbm2ddl.auto=create But I get an exception because the schemas, defined in the entity classes by annotations, are not created before the tables are created. Now I am searching for an opportunity to create the schemas before hibernate.hbm2ddl.auto runs. To remove the schemas is not an opportunity for me, because I need them for my program.

My problem is pretty much the same like this. The different is I do not use spring, so the solution does not work for me.


Solution

  • Assuming that you're using H2 database, you may provide init command to run with jdbc connection url. For example:

    your.jdbc.url=jdbc:h2:mem:;DB_CLOSE_DELAY=-1;INIT=create schema IF NOT EXISTS your_schema
    

    Unfortunately, the issue on hibernate jira is still unresolved https://hibernate.atlassian.net/browse/HHH-5665