63356

Hibernate gives error error as “Access to DialectResolutionInfo cannot be null when 'hibernate.

Hibernate works fine when there is internet connection. But when there is no internet connection, it gives me

Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

error. I think my application is trying to access the internet connectivity when running. The detail error that I get is given below:-

Dec 22, 2015 6:17:43 PM org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator initiateService WARN: HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections Initial SessionFactory creation failed.org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set 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:104) at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:71) at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:209) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206) at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843) at com.pos.admin.admin_module.admin_module.hibernatefiles.hibernate.HibernateUtil.buildSessionFactory(HibernateUtil.java:32) at com.pos.admin.admin_module.admin_module.hibernatefiles.hibernate.HibernateUtil.getSessionFactory(HibernateUtil.java:44) at com.pos.admin.admin_module.main.AdminModule.start(AdminModule.java:21) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163(Unknown Source) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(Unknown Source) at com.sun.javafx.application.PlatformImpl.lambda$null$174(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(Unknown Source) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$149(Unknown Source) at java.lang.Thread.run(Unknown Source) Exception in Application start method java.lang.reflect.InvocationTargetException 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 com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source) at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source) 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 sun.launcher.LauncherHelper$FXHelper.main(Unknown Source) Caused by: java.lang.RuntimeException: Exception in Application start method at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$156(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.ExceptionInInitializerError at com.pos.admin.admin_module.admin_module.hibernatefiles.hibernate.HibernateUtil.buildSessionFactory(HibernateUtil.java:39) at com.pos.admin.admin_module.admin_module.hibernatefiles.hibernate.HibernateUtil.getSessionFactory(HibernateUtil.java:44) at com.pos.admin.admin_module.main.AdminModule.start(AdminModule.java:21) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163(Unknown Source) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(Unknown Source) at com.sun.javafx.application.PlatformImpl.lambda$null$174(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(Unknown Source) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$149(Unknown Source) ... 1 more 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:104) at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:71) at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:209) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206) at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843) at com.pos.admin.admin_module.admin_module.hibernatefiles.hibernate.HibernateUtil.buildSessionFactory(HibernateUtil.java:32) ... 11 more Exception running application com.pos.admin.admin_module.main.AdminModule

My pom.xml file

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.pos.admin.admin_module</groupId> <artifactId>admin_module</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>admin_module</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <!-- <build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.3</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </pluginManagement> </build> --> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <!-- <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>5.0.5.Final</version> </dependency> --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>4.3.5.Final</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.37</version> </dependency> <!-- <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>4.3.5.Final</version> </dependency> --> <!-- <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>5.2.2.Final</version> </dependency> --> <!-- <dependency> <groupId>javax.el</groupId> <artifactId>javax.el-api</artifactId> <version>2.2.4</version> </dependency> <dependency> <groupId>org.glassfish.web</groupId> <artifactId>javax.el</artifactId> <version>2.2.4</version> </dependency> --> </dependencies> </project>

My hibernate configuration (hibernate.cfg.xml) file

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost/point_of_sales</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password"> </property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.current_session_context_class">thread</property> <property name="hibernate.show_sql">true</property> <!-- <property name="hbm2ddl.auto">update</property> --> <mapping class="com.pos.admin.admin_module.hibernatefiles.dto.Category"/> <mapping class="com.pos.admin.admin_module.hibernatefiles.dto.ProductHeader"/> <mapping class="com.pos.admin.admin_module.hibernatefiles.dto.PurchaseDetail"/> <mapping class="com.pos.admin.admin_module.hibernatefiles.dto.PurchaseHeader"/> <mapping class="com.pos.admin.admin_module.hibernatefiles.dto.SalesDetail"/> <mapping class="com.pos.admin.admin_module.hibernatefiles.dto.SalesHeader"/> <mapping class="com.pos.admin.admin_module.hibernatefiles.dto.Settings"/> <mapping class="com.pos.admin.admin_module.hibernatefiles.dto.Unit"/> <mapping class="com.pos.admin.admin_module.hibernatefiles.dto.User"/> <mapping class="com.pos.admin.admin_module.hibernatefiles.dto.Supplier"/> <!-- <mapping class="com.pos.storekeeper.storekeeper_module.hibernateFiles.dto.Supplier"/> <mapping class="com.pos.storekeeper.storekeeper_module.hibernateFiles.dto.PurchaseHeader"/> <mapping class="com.pos.storekeeper.storekeeper_module.hibernateFiles.dto.ProductHeader"/> <mapping class="com.pos.storekeeper.storekeeper_module.hibernateFiles.dto.Category"/> <mapping class="com.pos.storekeeper.storekeeper_module.hibernateFiles.dto.Unit"/> --> <!-- <mapping class="com.pos.storekeeper.storekeeper_module.hibernateFiles.dto.User"/> --> <!-- <mapping class="com.pos.admin.admin_module.admin_module.main.Cart1"/> --> </session-factory> </hibernate-configuration>

HibernateUtil class where I create Configuration and Session objects

public class HibernateUtil { private static SessionFactory sessionFactory; private static SessionFactory buildSessionFactory() { try { // Create the SessionFactory from hibernate-annotation.cfg.xml Configuration configuration = new Configuration(); try{ configuration.configure("hibernate.cfg.xml"); }catch(Exception e){ System.out.println("Exception while handling configureation file :" + e.getMessage()); System.out.println("asfsdaf " + configuration); } System.out.println("Hibernate Annotation Configuration loaded"); ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build(); System.out.println("Hibernate Annotation serviceRegistry created"); SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry); return sessionFactory; } catch (Throwable ex) { System.err.println("Initial SessionFactory creation failed." + ex); ex.printStackTrace(); throw new ExceptionInInitializerError(ex); } } public static SessionFactory getSessionFactory() { if(sessionFactory == null) sessionFactory = buildSessionFactory(); return sessionFactory; } public static void closeSessionFactory(){ if(!sessionFactory.isClosed()){ System.out.println("Closing SessionFactory"); sessionFactory.close(); } } }

I want to fix this issue because internet connectivity cannot be always available. Thank you

Answer1:

to use hibernate offline you will have to change your dtd in your xml mapping and configuration files.make sure hibernate jar is in your classpath

for xml mapping file <!DOCTYPE hibernate-mapping SYSTEM "classpath://org/hibernate/hibernate-mapping-3.0.dtd">

for configuration file :

<!DOCTYPE hibernate-configuration SYSTEM "classpath://org/hibernate/hibernate-configuration-3.0.dtd">

http://www.journaldev.com/2959/how-to-configure-hibernate-cfg-xml-to-work-offline

Answer2:

Try to remove SessionFactory from this:

SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);

To be:

sessionFactory = configuration.buildSessionFactory(serviceRegistry);

Or add this buildSessionFactory() like this:

private static SessionFactory sessionFactory = buildSessionFactory();

Recommend

  • FXML ClassNotFoundException
  • NullPointerException loading fxml file from javafx applet
  • Why is this code not working? Hangman
  • Dependency conflict in integrating with Cloudera Hbase 1.0.0
  • How to combine two lists together?
  • Declare PtrSafe Compatibility in Excel
  • Implementing Oracle.Web.dll, Oracle.DataAccess.dll 64-bit failed on Windows Server 2008 with IIS 7.5
  • help('modules') crashing? Not sure how to fix
  • Add Windows Feature from C#
  • Can I use AllJoyn Framework for Wifi Direct in iOS?
  • how do i write assembly code from c#?
  • 550 Access denied - Invalid HELO name
  • CakePHP ACL tutorial initDB function warnings
  • How to revert to previous XCode version?
  • How can I speed up CURL tasks?
  • What does 'Language neutral' mean with regard to MAKELANGID?
  • SharedPreferences or SQLite Database?
  • How to determine if there are bytes available to be read from boost:asio:serial_port
  • How do I exclude a dependency in provided scope when running in Maven test scope?
  • How can I sort a a table with VBA with given text condition?
  • Problem deserializing objects from cache on MyBatis 3/Java
  • Is there a way to do normal logging with EureakLog?
  • Time complexity of a program which involves multiple variables
  • Admob requires api-13 or later can I not deploy on old API-8 phones?
  • Test if a set exists before trying to drop it
  • Unity3D & Android: Difference between “UnityMain” and “main” threads?
  • Spark fat jar to run multiple versions on YARN
  • Asynchronous UI Testing in Xcode With Swift
  • Scrapy recursive link crawler
  • Spring Data JPA custom method causing PropertyReferenceException
  • Display issues when we change from one jquery mobile page to another in firefox
  • NetLogo BehaviorSpace - Measure runs using reporters
  • Spray.io: When (not) to use non-blocking route handling?
  • Perl system calls when running as another user using sudo
  • Python - Map / Reduce - How do I read JSON specific field in using DISCO count words example
  • SVN: Merging two branches together
  • Hibernate gives error error as “Access to DialectResolutionInfo cannot be null when 'hibernate.
  • coudnt use logback because of log4j
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?