Simon Sobisch
Simon Sobisch

Reputation: 7297

SQLGrammarException: Could not get list of suggested identity strategies from database (SQL-Server colllation Latin1_General_BIN)

I've created a new Persistence Unit in RapidClipse (Eclipse Neon with Hibernate [and other] plugins included) using a new connection profile to an SQL-Server 2014. "Test connection" works fine - "Ping succeeded!".

The next dialog "Generate Entities from Tables -> Select tables" shows all tables, but on choosing one and using "Generate Entities from Tables -> Table Associations" fails:

Hibernate metadata on BIN collation

This does only happen when using a case sensitive collation - the database uses "Latin1_General_BIN", if I switch it to "Latin1_General_CI_AS" hibernate doesn't show any problems with the identity strategies but I cannot change the database collation on the production server.

Question: Is there a way to fix the "Could not get list of suggested identity strategies from database." error without changing the collation?

Stack trace:

org.hibernate.exception.SQLGrammarException: Could not get list of suggested identity strategies from database. Probably a JDBC driver problem. 
    at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:106)
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
    at org.hibernate.cfg.reveng.dialect.SQLServerMetaDataDialect.getSuggestedPrimaryKeyStrategyName(SQLServerMetaDataDialect.java:69)
    at org.hibernate.cfg.reveng.PrimaryKeyProcessor.processPrimaryKey(PrimaryKeyProcessor.java:109)
    at org.hibernate.cfg.reveng.JDBCReader.readDatabaseSchema(JDBCReader.java:183)
    at org.hibernate.cfg.reveng.JDBCReader.readDatabaseSchema(JDBCReader.java:125)
    at org.hibernate.cfg.reveng.JDBCReader.readDatabaseSchema(JDBCReader.java:118)
    at org.hibernate.cfg.JDBCBinder.readDatabaseSchema(JDBCBinder.java:154)
    at org.hibernate.cfg.JDBCBinder.readFromDatabase(JDBCBinder.java:119)
    at org.hibernate.cfg.JDBCMetaDataConfiguration.readFromJDBC(JDBCMetaDataConfiguration.java:174)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.jboss.tools.hibernate.runtime.common.Util.invokeMethod(Util.java:43)
    at org.jboss.tools.hibernate.runtime.common.AbstractConfigurationFacade.readFromJDBC(AbstractConfigurationFacade.java:208)
    at xdev.eclipse.internal.hibernate.metadata.MetadataUtils.lambda$1(MetadataUtils.java:173)
    at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:63)
    at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:107)
    at xdev.eclipse.internal.hibernate.metadata.MetadataUtils.readDatabaseMetadata(MetadataUtils.java:146)
    at xdev.eclipse.internal.server.core.ui.wizard.generateentities.AssociationsWizardPage.init(AssociationsWizardPage.java:849)
    at xdev.eclipse.internal.server.core.ui.wizard.generateentities.AssociationsWizardPage.lambda$2(AssociationsWizardPage.java:789)
    at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2240)
    at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2267)
    at xdev.eclipse.internal.server.core.ui.wizard.generateentities.AssociationsWizardPage.lambda$3(AssociationsWizardPage.java:796)
    at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Ungültiger Objektname 'INFORMATION_SCHEMA.Columns'.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1522)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:404)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:350)
    at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1716)
    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.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:285)
    at org.hibernate.cfg.reveng.dialect.SQLServerMetaDataDialect.getSuggestedPrimaryKeyStrategyName(SQLServerMetaDataDialect.java:36)
    ... 23 more

Upvotes: 0

Views: 797

Answers (1)

Michele Mariotti
Michele Mariotti

Reputation: 7469

The error is quite self-explanatory: Probably a JDBC driver problem.

You may want to check if there's an updated driver.

Apart from this, I cannot see the reason why you want to generate entities from production db, istead of using production (altered) schema (only for generation!).

You can just

  1. export'n'import the production db (just the schema if it's a big one) in development environment
  2. change the collation in dev-env
  3. generate entities
  4. revert collation / re-import (in dev-env, so you can test your new entities)
  5. it should work fine (even in production, without any db modification) when you'll deploy your app

Since the error is related to Ungültiger Objektname 'INFORMATION_SCHEMA.Columns', which is used only by generation procedure, doing this way it's probably the best-effort solution.

If it's not working even this way, then it's not related to Eclipse/RapidClipse, but it's a real compatibility problem between Hibernate and the JDBC driver.

In this case, maybe there's some specific hibernate/jdbc configuration parameter to handle binary collation (maybe a specific dialect).

Upvotes: 0

Related Questions