-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 15 posts ] 
Author Message
 Post subject: Schema update fails on MS SQL-Server
PostPosted: Thu Nov 16, 2017 10:45 am 
Newbie

Joined: Thu Nov 16, 2017 3:42 am
Posts: 9
Hi,
the org.hibernate.tool.hbm2ddl.SchemaUpdate#execute() fails on a Microsoft SQLServer 2008 database which contains a hyphen in the database name. In that case the database name in the fully qualified table name has to be wrapped by quotes.

Example:

does not work:

Code:
alter table serie-m.paul.MOMS_SPLIT_DOC add TYPE_STRING varchar(32)


works:

Code:
alter table "serie-m".paul.MOMS_SPLIT_DOC add TYPE_STRING varchar(32)


Exception is:

Code:
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Falsche Syntax in der Nähe von '-'.
   at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
   at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1515)
   at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:792)
   at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:689)
   at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
   at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
   at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:180)
   at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:155)
   at com.microsoft.sqlserver.jdbc.SQLServerStatement.execute(SQLServerStatement.java:662)
   at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)


Is this a bug or is it possible to get it working somehow ? My code is very simple:

Code:
       
        StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder()
            .applySettings(settings)
            .configure(sessionFactoryCfgUrl)
            .build();
       
        MetadataSources metadataSources = new MetadataSources( standardRegistry );
       
        // add mappings...
       
        Metadata metadata = metadataSources.getMetadataBuilder()
                        .applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE )
                        .build();
       
        SchemaUpdate schmaUpdate = new SchemaUpdate();
        schmaUpdate.execute(EnumSet.of(TargetType.DATABASE), metadata, standardRegistry);
        ...


Thank you.


Top
 Profile  
 
 Post subject: Re: Schema update fails on MS SQL-Server
PostPosted: Thu Nov 16, 2017 11:18 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1638
Location: Romania
Try setting this configuration property:

Code:
<property
    name="hibernate.globally_quoted_identifiers"
    value="true"
/>

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Schema update fails on MS SQL-Server
PostPosted: Thu Nov 16, 2017 11:47 am 
Newbie

Joined: Thu Nov 16, 2017 3:42 am
Posts: 9
Thank you for the fast response. I will try immediately...


Top
 Profile  
 
 Post subject: Re: Schema update fails on MS SQL-Server
PostPosted: Thu Nov 16, 2017 12:33 pm 
Newbie

Joined: Thu Nov 16, 2017 3:42 am
Posts: 9
Property hibernate.globally_quoted_identifiers=true does not work unfortunately. At schema update the code in org.hibernate.mapping.Table#sqlAlterStrings (line 450) still gets the qualified table name wrong, because TableInformationImp#tableName provides it without quotes, likely because its' identifierHelper (which has NormalizingIdentifierHelperImpl#globallyQuoteIdentifiers = true) is not used at #getName().


Top
 Profile  
 
 Post subject: Re: Schema update fails on MS SQL-Server
PostPosted: Thu Nov 16, 2017 1:25 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1638
Location: Romania
Which version of Hibernate are you using?

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Schema update fails on MS SQL-Server
PostPosted: Fri Nov 17, 2017 7:35 am 
Newbie

Joined: Thu Nov 16, 2017 3:42 am
Posts: 9
I'm using Hibernate core 5.2.12.


Top
 Profile  
 
 Post subject: Re: Schema update fails on MS SQL-Server
PostPosted: Fri Nov 17, 2017 8:05 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1638
Location: Romania
Sounds like a bug. Use the the JPA test case template to build the replicating test case and open a Jira issue for this.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Schema update fails on MS SQL-Server
PostPosted: Fri Nov 17, 2017 8:18 am 
Newbie

Joined: Thu Nov 16, 2017 3:42 am
Posts: 9
OK.


Top
 Profile  
 
 Post subject: Re: Schema update fails on MS SQL-Server
PostPosted: Mon Nov 20, 2017 5:48 am 
Newbie

Joined: Thu Nov 16, 2017 3:42 am
Posts: 9
Created issue https://hibernate.atlassian.net/browse/HHH-12106 for it. Thanks!


Top
 Profile  
 
 Post subject: Re: Schema update fails on MS SQL-Server
PostPosted: Mon Nov 20, 2017 6:08 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1638
Location: Romania
Thanks.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Schema update fails on MS SQL-Server
PostPosted: Wed Nov 22, 2017 10:22 am 
Newbie

Joined: Thu Nov 16, 2017 3:42 am
Posts: 9
How can I get this issue fixed? Do I have to assign someone to it (currently unassigned), or does it wait for votes ?


Top
 Profile  
 
 Post subject: Re: Schema update fails on MS SQL-Server
PostPosted: Wed Nov 22, 2017 3:50 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1638
Location: Romania
There are two ways to get it fixed:

1. If you are in a hurry, you can fix it yourself and send us a Pull request
2. If you are not, you can wait until we are done with other more high priority tasks

Either way, you will also have to wait for a future release

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Schema update fails on MS SQL-Server
PostPosted: Thu Nov 23, 2017 10:22 am 
Newbie

Joined: Thu Nov 16, 2017 3:42 am
Posts: 9
vlad, thanks a lot.


Top
 Profile  
 
 Post subject: Re: Schema update fails on MS SQL-Server
PostPosted: Thu Dec 21, 2017 9:50 am 
Newbie

Joined: Thu Nov 16, 2017 3:42 am
Posts: 9
Vlad, thanks a lot for the fix.
Is there any chance to get this into the 5.2 branch also ?


Top
 Profile  
 
 Post subject: Re: Schema update fails on MS SQL-Server
PostPosted: Thu Dec 21, 2017 6:12 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1638
Location: Romania
Gail will decide if this will be back-ported. It's her responsibility.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 15 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.