0

我正在 Netbeans 中开发 Netbeans Maven Java 应用程序。我正在研究 Hibernate,我遇到了这些错误。我用作hibernate.cfg.xmlHibernate 配置并在文件中定义sqljdbc4了 sql server 的驱动程序hibernate.cfg.xml。我的问题是,MSSQL 驱动程序或依赖项或 hibernate.cfg.xml 是否有任何问题?

我的 hibernate.cfg.xml 包含以下代码

<?xml version="1.0" encoding="utf-8"?> 
<!DOCTYPE hibernate-configuration SYSTEM  "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.dialect">
      org.hibernate.dialect.SQLServer2008Dialect
    </property>
    <property name="hibernate.connection.driver_class">
      com.microsoft.sqlserver.jdbc.SqlServerDriver
    </property>    
    <!-- Assume test is the database name -->
    <property name="hibernate.connection.url">
      jdbc:sqlserver://localhost:1433;databaseName=TestDatabase;
    </property>
    <property name="hibernate.connection.username">
      sa
    </property>
    <property name="hibernate.connection.password">
      abdullah242
    </property>
    <property name="show_sql">true</property>    
    <!-- List of XML mapping files -->
    <mapping class="com.infiniteskills.data.entities.Customers" />
  </session-factory>
</hibernate-configuration>

****编译结果****

  1. 正在扫描项目...

构建hibernate-course 1.0-SNAPSHOT

***The POM for com.microsoft.sqlserver:sqljdbc4:jar:4.0 is missing, no dependency information available***

--- exec-maven-plugin:1.2.1:exec (default-cli) @ hibernate-course ---

 1. DEBUG - Logging Provider: org.jboss.logging.Log4jLoggerProvider
---
---
---
---

WARN - HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections
WARN - HHH000342: Could not obtain connection to query metadata : The application must supply JDBC connections
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:244)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:208)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
    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:217)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:692)
    at com.infiniteskills.data.HibernateUtil.buildSessionFactory(HibernateUtil.java:18)
    at com.infiniteskills.data.HibernateUtil.<clinit>(HibernateUtil.java:11)
    at com.infiniteskills.data.Application.main(Application.java:9)
Caused by: 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:234)
    ... 15 more
Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.infiniteskills.data.Application.main(Application.java:9)
Caused by: java.lang.RuntimeException: There was an error building the factory
    at com.infiniteskills.data.HibernateUtil.buildSessionFactory(HibernateUtil.java:22)
    at com.infiniteskills.data.HibernateUtil.<clinit>(HibernateUtil.java:11)
    ... 1 more
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 2.019s
Finished at: Fri Feb 05 09:21:47 PKT 2016
Final Memory: 6M/109M
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project hibernate-course: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

**For more information about the errors and possible solutions, please read the following articles:**
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
4

1 回答 1

0

看起来(通过堆栈跟踪中的行号)您使用Hibernate 5. 我可以做一个假设——在HibernateUtil你配置Hibernate 5中使用配置的方式Hibernate 4。这是完全不正确的,请参阅以获取有关配置的信息Hibarnate 5

如果我的假设是正确的,那么异常的原因——Configuration类在 call 期间丢失了来自hibernate.cfg.xml, include的所有信息。hibernate.dialectconfigure(serviceRegistry)

于 2016-02-05T07:53:20.313 回答