Fix HHH-12106 Database name not quoted at schema update on MS-SQLServer not working


#1

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 '-'.

#2

We have the SqlServerQuoteSchemaTest that works just fine.


#3

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]

#4

Try to supply a Pull Request which replicates your issue.


#5

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.


#7

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)

#8

But why do you need the database name in your qualified name?

The database can be implied from the JDBC URL string:

jdbc:sqlserver://localhost;instance=SQLEXPRESS;databaseName=hibernate_orm_test

#9

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.


#10

Sends us a Pull Request which replicates the issue based on the ones we have committed previously. We will investigate it afterwards.


#11

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 ?


#12

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.


#13

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 ?


#14

Just adapt the existing one, replicate the issue and send a Pull Request. Thanks.


#15

Ok, I will try. Thank you!