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]
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Falsche Syntax in der Nähe von '-'.
We have the
SqlServerQuoteSchemaTest that works just fine.
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]
Try to supply a Pull Request which replicates your issue.
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.
In the DDL to CREATE the table the catalog name is not used in despite to the update DDL:
create table [paul].[my_entity] (
[id] int not null,
primary key ([id])
alter table seriem.[paul].[my_entity]
add [title] varchar(255)
But why do you need the database name in your qualified name?
The database can be implied from the JDBC URL string:
Thanks for the hint. But after I added the database name to the JDBC URL it still appears in the DDL:
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.
Sends us a Pull Request which replicates the issue based on the ones we have committed previously. We will investigate it afterwards.
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 ?
Any change to the codebase must have an associated test case. We need the test case to see the impact on other databases as well.
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 ?
Just adapt the existing one, replicate the issue and send a Pull Request. Thanks.
Ok, I will try. Thank you!
Hi @grischapaul ,
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.