hibernate表名模式不能为NULL或为空

时间:2016-10-20 11:37:03

标签: eclipse hibernate

无法在eclipse环境中使用hibernate从db到java代码进行逆向工程。

创建hibernate控制台配置后,我看到错误: 无法从数据库获取表列表。可能是JDBC驱动程序问题。 堆栈跟踪 表名模式不能为NULL或为空。

我不确定应该给出这个表名模式的位置。

的env

  • eclipse neon
  • hibernate tools 5.1.1
  • mysql connector 6.0.4
  • jdk 1.8

配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                                         "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
 <session-factory name="">
  <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  <property name="hibernate.connection.url">jdbc:mysql://localhost/test</property>
  <property name="hibernate.connection.username">root</property>
  <property name="hibernate.connection.password"/>
  <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
 </session-factory>
</hibernate-configuration>

完整堆栈跟踪

  

org.jboss.tools.hibernate.runtime.spi.HibernateException:无法   获取数据库中的表列表。可能是JDBC驱动程序问题。   已配置架构:null已配置目录:null可用架构:   可用目录:information_schema mysql performance_schema   测试

     

在   org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter $ 2.execute(LazyDatabaseSchemaWorkbenchAdapter.java:139)     在   org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:63)     在   org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:108)     在   org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter.readDatabaseSchema(LazyDatabaseSchemaWorkbenchAdapter.java:125)     在   org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter.getChildren(LazyDatabaseSchemaWorkbenchAdapter.java:65)     在   org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:104)     在   org.eclipse.ui.progress.DeferredTreeContentManager $ 1.run(DeferredTreeContentManager.java:231)     在org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)引起的   by:java.sql.SQLException:表名模式不能为NULL或   空。在   com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:569)     在   com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:537)     在   com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:527)     在   com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:512)     在   com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:480)     在   com.mysql.cj.jdbc.DatabaseMetaData.getTables(DatabaseMetaData.java:3844)     在   org.hibernate.cfg.reveng.dialect.JDBCMetaDataDialect.getTables(JDBCMetaDataDialect.java:27)     在   org.hibernate.cfg.reveng.TableProcessor.processTables(TableProcessor.java:39)     在   org.hibernate.cfg.reveng.JDBCReader.readDatabaseSchema(JDBCReader.java:58)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:497)at   org.jboss.tools.hibernate.runtime.common.Util.invokeMethod(Util.java:43)     在   org.jboss.tools.hibernate.runtime.common.AbstractJDBCReaderFacade.readDatabaseSchema(AbstractJDBCReaderFacade.java:52)     在   org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter $ 2.execute(LazyDatabaseSchemaWorkbenchAdapter.java:134)     ......还有7个

1 个答案:

答案 0 :(得分:1)

You have not configured default schema so hibernate doesn't know where it should get tables. You can do it like this:

<property name="hibernate.connection.url">jdbc:mysql://localhost/test?currentSchema=shema_name</property>

Also watch probable answer here