无法逆向工程以在eclipse中使用hibernate生成pojo

时间:2016-11-21 09:22:52

标签: java eclipse hibernate sql-server-2014

我在使用hibernate 5时遇到了来自数据库的逆向工程问题。我能够生成hibernate.reveng.xml文件,但是当我使用Hibernate代码生成配置运行时,它会给出如下所述的错误。

我尝试过添加“hibernate”。我的xml文件,但同样的事情,我可以生成hibernate.reveng.xml但不能运行Hibernate代码生成配置。

这是我的xml文件:

<hibernate-configuration>
 <session-factory>
  <property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
  <property name="connection.password">Password123!</property>
  <property name="connection.url">jdbc:sqlserver://localhost:1433;databaseName=TestDB</property>
  <property name="connection.username">sa</property>
  <property name="dialect">org.hibernate.dialect.SQLServer2012Dialect</property>
 </session-factory>
</hibernate-configuration>

这是我面临的错误。

org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100)
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137)
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:257)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:231)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:240)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
    at org.hibernate.cfg.JDBCMetaDataConfiguration.handleTypes(JDBCMetaDataConfiguration.java:231)
    at org.hibernate.cfg.JDBCMetaDataConfiguration.getMetadataCollector(JDBCMetaDataConfiguration.java:90)
    at org.hibernate.cfg.JDBCMetaDataConfiguration.getMetadataBuildingContext(JDBCMetaDataConfiguration.java:105)
    at org.hibernate.cfg.JDBCMetaDataConfiguration.readFromJDBC(JDBCMetaDataConfiguration.java:123)
    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:216)
    at org.hibernate.eclipse.console.common.ConsoleExtension$2.execute(ConsoleExtension.java:308)
    at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:63)
    at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:108)
    at org.hibernate.eclipse.console.common.ConsoleExtension.buildConfiguration(ConsoleExtension.java:266)
    at org.hibernate.eclipse.console.common.ConsoleExtension.runExporters(ConsoleExtension.java:174)
    at org.hibernate.eclipse.console.common.ConsoleExtension.launchExporters(ConsoleExtension.java:110)
    at org.hibernate.eclipse.launch.CodeGenerationLaunchDelegate.launch(CodeGenerationLaunchDelegate.java:266)
    at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:885)
    at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:739)
    at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1039)
    at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1256)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

2 个答案:

答案 0 :(得分:0)

试试这个。

<property name="dialect">org.hibernate.dialect.SQLServer2012Dialect</property>更改为<property name="hibernate.dialect">org.hibernate.dialect.SQLServer2012Dialect</property>

答案 1 :(得分:0)

我最终删除了整个配置文件并重做所有步骤,根据我发布的内容对我的pojo进行逆向工程,现在正在运行。但我不明白为什么。