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.
Hibernate schema generation strategies You can encapsulate schema changes in migration scripts and use a tool, like Flyway, to apply the migration scripts upon starting the application. You can generate or update the database schema from the JPA and Hibernate entity mappings using the hbm2ddl. auto tool.
create: creates the schema, destroying previous data. create-drop: drop the schema when the SessionFactory is closed explicitly, typically when the application is stopped.
auto Create : If the value is CREATE then the hibernate first drops the existing tables data and structure, then creates new tables and executes the operations on the newly created tables. The only problem with the value “create” is, we lose existing table data.
hibernate.hbm2ddl.auto. Automatically validates or exports schema DDL to the database when the SessionFactory is created. With create-drop , the database schema will be dropped when the SessionFactory is closed explicitly.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With