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

时间:2014-07-28 12:47:50

标签: java hibernate jboss reverse-engineering

您好我正在尝试使用JBoss Hibernate Tools进行逆向工程。我正在使用来自eclipse市场的eclipse luna和最新的hibernate jboss工具。当我尝试配置hibernate工具配置时,配置完成后,当我展开树并展开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的连接是成功构建的,因为在Database explore的帮助下,eclipse make connection成功并且还显示了所有表。我使用的是Hibernate 4.3和最新的MySQL driver 5.1.31。以下是我配置的屏幕截图。

  1. enter image description here

  2. enter image description here

  3. 以下是我的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>
    

4 个答案:

答案 0 :(得分:6)

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

答案 1 :(得分:4)

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

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

答案 2 :(得分:1)

我使用以下JDBC驱动程序,并且问题得到解决。

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

答案 3 :(得分:0)

我遇到了同样的问题,但是使用MS SQL Server而DB名称中没有“ - ”。 您可以尝试设置“可选”属性hibernate.default_schema。