在 Netbeans 中调试 Maven Java 应用程序时出现问题

Issue in Debuging Maven Java Application in Netbeans

我正在 Netbeans 中开发 Netbeans Maven Java 应用程序。我在 Hibernate 上工作时遇到了这些错误。我使用 hibernate.cfg.xml 作为 Hibernate 配置,并在 hibernate.cfg.xml 文件中定义了 sql 服务器的 sqljdbc4 驱动程序。我的问题是,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. 正在扫描项目...

构建休眠课程 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

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

的信息

如果我的假设是正确的,异常的原因——Configuration class 在调用 configure(serviceRegistry) 期间丢失了来自 hibernate.cfg.xml 的所有信息,包括 hibernate.dialect ].