I have been struggling with database schemas and hibernates default schema support (hibernate.default_schema). I use schema names that needs escaping, where schemas for H2 should be escaped with quotes e.g. “(my) weird schema-name” and for SQL Server with square brackets e.g. [(my) weird schema-name].
I followed some of the forum threads that states, you should just escape the schema name with quotes or square brackets before setting hibernate.default_schema. It kind of works. Every generated SQL statement now contains an escaped schema name. But….. Hbm2dll schema update doesn’t seem to work. The first startup successfully create all the tables, but the second startup writes a lot of error messages stating that the table already exists.
For further information see. https://forum.hibernate.org/viewtopic.php?f=1&t=1031729
Since this is quite severe for our usage, we have forked hibernate 4.2.11, written a test that shows the error, and fixed it with fast fix that just removes the escaping before the invocation to org.hibernate.tool.hbm2ddl.DatabaseMetadata#getTableMetadata(). It is building on our CI environment and is added to our repository.
Would you accept such a pull request?
|