Hello,
Last year I posted a problem in old forum and created HHH-12106 which should habe been fixed in hibernate 5.3.1-final according to the versions’ change log. The problem was that a database name containing a hyphen in Microsoft SQL-Server is not quoted at hibernate schema update. I tested it today with version 5.3.1-final and the problem still occurs:
Hibernate: alter table serie-m.paul.MOMS_SPLIT_DOC add TYPE_STRING varchar(32)
[org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table serie-m.paul.MOMS_SPLIT_DOC add TYPE_STRING varchar(32)" via JDBC Statement]
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Falsche Syntax in der Nähe von '-'.
I see in test property hibernate.globally_quoted_identifiers=true is set. Do you confirm that this property has to be used in general (javadoc: Should all database identifiers be quoted) just because one identifier (in this case the database name) should be quoted?
I used it also, but it still does not work. The schema and table name is now wrapped into brackets, but the database name (serie-m in this case) not:
Hibernate: alter table serie-m.[paul].[MOMS_SPLIT_DOC] add [TYPE_STRING] varchar(32)
[org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table serie-m.[paul].[MOMS_SPLIT_DOC] add [TYPE_STRING] varchar(32)" via JDBC Statement]
I can reproduce it with SqlServerQuoteSchemaTest when using MS-SQL-Server 2008 and appropriate Dialect org.hibernate.dialect.SQLServer2008Dialect which is very old of course. Then the update DDL contains the unquoted database name:
alter table serie-m.[my-schema].[my_entity]
add [title] varchar(255);
With SQL-Server 2012 and appropriate Dialect version the DDL contains no database name. This might be caused by JDBC DatabaseMetadata which probably does not supply a catalog resp. database name (I did not debug so deep). But in principal the code is not prepared to quote database name though property hibernate.globally_quoted_identifiers=true and it is also not tested by SqlServerQuoteSchemaTest DDL comparison string at Line 154, where only schema and entity name is quoted.
Thanks for the hint. But after I added the database name to the JDBC URL it still appears in the DDL:
my URL: hibernate.connection.url=jdbc:sqlserver://mssql-2008-std.hq.kwsoft.de:1433;instance=MSSQL-2008-STD;databaseName=serie-m
DDL statement:
alter table serie-m.[paul].[my_entity]
add [title] varchar(255)
I don’t need the database name in the qualified name, it is added by Hibernate for some reason to the alter table DDL statements’ table name.
Puh, a lot of work for me for what you already have resp. could adapt easily. Simply run SqlServerQuoteSchemaTest against your MS-SQL-Server and you should see the non-quoted database name in the full qualified entity name in the “alter table add columns” DDL statement.
Still want me to send a pull request ?
The already existing test case is MS-SQL-specific, according to its name SqlServerQuoteSchemaTest. Can I adapt it or do you want me to create an new one ?
Once you have a modified test case, please create an associated new JIRA so that we can track this issue.
From what you say, it looks like we are doing something wrong indeed but I checked the code and we are supposed to quote the catalog name (which is the database name in this case).
I don’t have SQL Server handy to check that but could you add a breakpoint in org.hibernate.mapping.Table#sqlAlterStrings() and check what it is doing. As you can see, we have some code to quote everything so there’s something fishy here.