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.