12

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.

Community
  • 1
  • 1
johzi
  • 137
  • 6

2 Answers2

5

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

kamil
  • 3,482
  • 1
  • 40
  • 64
  • Thanks for your help. It worked with javax.persistence.jdbc.url=jdbc:h2:mem:test:;DB_CLOSE_DELAY=-1;INIT=\\;runscript from '~/workspace/project/src/test/resources/sql/createschema.sql'; in the sql i create all my schemas – johzi Jul 22 '14 at 09:01
3

Since Hibernate 5 there is a cleaner and more db-independent way, which also works with hsqldb. Add this configuration property:

hibernate.hbm2dll.create_namespaces=true
Ken Koster
  • 408
  • 3
  • 9