javahibernatemavenmssql-jdbchibernate.cfg.xml

Issue in Debuging Maven Java Application in Netbeans


I am working on a Netbeans Maven Java Application in Netbeans. I am working on Hibernate I got these errors. I used hibernate.cfg.xml as Hibernate configuration and defined sqljdbc4 driver of sql server in hibernate.cfg.xml file. My question is, Is there any issue with MSSQL Driver or any issue with dependencies or with hibernate.cfg.xml?

My hibernate.cfg.xml contains following code

<?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>

****Compiled results****

  1. Scanning for projects...

Building 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

Solution

  • Looks like (by line numbers in the stack trace) you use Hibernate 5. I can make an assumption — in the HibernateUtil you configure Hibernate 5 using the way of Hibernate 4 configuration. It is entirely incorrect, refer this for information about configuration Hibarnate 5.

    If my assumption is correct, the reason of the exception — Configuration class losts all information from hibernate.cfg.xml, include hibernate.dialect, during call configure(serviceRegistry).