| I also was wondered why Hibernate tries to remove unexisting tables and foreign keys. This is very confusing behavior and it has a big performance impact. Also the naming here is really confusing and IMHO it should be like:
- create: which corresponds to create-only
- create-drop: and it doesn't have existing analog and this is a real subject of the issue.
- drop-create: which corresponds to create
- drop-create-drop: which corresponds to create-drop
For example I have integrations tests where each tests case recreates H2 db in memory in MySQL mode. But in the same time hibernate dialect is set to MariaDB (as in production) and the dialect supports “DROP FOREIGN KEY IF NOT EXISTS” statements while original MySQL doesn’t supports the “IF NOT EXISTS”. So H2 in MySQL model is also doesn’t supports the “IF NOT EXISTS” statement. So during start it creates an empty H2 DB, then Hibernate tries to delete all unexisting tables and keys, it generates a lot of drop statements including “DROP FOREIGN KEY IF NOT EXISTS” which then failed in H2. Even with the halt_on_error I have a lot of errors in test logs and they makes me nervous. So I tried to use the create-only mode but it didn’t dropped tables and next test case was failed to execute. So it would be great if Hibernate will have the new mode “first create without checking that tables are already exists and after drop”. Or as another solution Hibernate can detect that the schema or db was just created and then skip the part with dropping the tables. |