繁体   English   中英

Jboss Hibernate Tools:读取错误模式 - 可能是 JDBC 驱动程序问题

[英]Jboss Hibernate Tools: Reading error schema - Probably a JDBC driver Issue

您好,我正在尝试使用 JBoss Hibernate 工具进行逆向工程。 我正在使用eclipse luna和来自 eclipse 市场的最新 hibernate jboss 工具。 当我尝试配置休眠工具配置时,配置完成后,当我展开树并展开database节点时,会生成以下错误:

<Reading Schema Error: Could not get list of suggested identity strategies from database. Probably a JDBC Driver Problem>

堆栈跟踪:

org.hibernate.exception.SQLGrammarException: Could not get list of suggested identity strategies from database. Probably a JDBC driver problem. 
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
at org.hibernate.cfg.reveng.dialect.MySQLMetaDataDialect.getSuggestedPrimaryKeyStrategyName(MySQLMetaDataDialect.java:55)
at org.hibernate.cfg.reveng.JDBCReader.processPrimaryKey(JDBCReader.java:429)
at org.hibernate.cfg.reveng.JDBCReader.readDatabaseSchema(JDBCReader.java:86)
at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter$2.execute(LazyDatabaseSchemaWorkbenchAdapter.java:126)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:63)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:107)
at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter.readDatabaseSchema(LazyDatabaseSchemaWorkbenchAdapter.java:115)
at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter.getChildren(LazyDatabaseSchemaWorkbenchAdapter.java:65)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:106)
at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:238)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-empirecl-test  like 'oauth_access_token'' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
at com.mysql.jdbc.Util.getInstance(Util.java:383)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1062)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4226)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4158)

我与 eclipse 的数据库连接是成功建立的,因为在 eclipse 的Database explore的帮助下成功建立连接并显示所有表。 我正在使用Hibernate 4.3和最新的MySQL driver 5.1.31 以下是我的配置的屏幕截图。

  1. 在此处输入图片说明

  2. 在此处输入图片说明

以下是我的hibernate.cfg.xml文件:

<hibernate-configuration>
<session-factory>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.password">password</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/nit-empirecl-test</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
</session-factory>
</hibernate-configuration>

我找到了解决方案,问题出在数据库名称上。 我不知道,但是 hibernate jboss 工具,不支持( - )数据库名称中的连字符。 当我用下划线更改名称时,配置将成功运行。

您应该设置hibernate默认架构(对于 sql server)

<property name="hibernate.default_schema">dbo</property>

我使用以下 JDBC 驱动程序,我的问题解决了。

<dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.47</version>
        </dependency>

我有同样的问题,但是使用 MS SQL Server 并且数据库名称中没有“-”。 您可以尝试设置“可选”属性 hibernate.default_schema。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM