gpt4 book ai didi

java - 当没有互联网连接时,Hibernate 给出错误错误 "Access to DialectResolutionInfo cannot be null when ' hibernate.dialect' not set"

转载 作者:行者123 更新时间:2023-11-30 08:42:55 28 4
gpt4 key购买 nike

当有 Internet 连接时,Hibernate 工作正常。但是当没有互联网连接时,它给了我

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

错误。我认为我的应用程序在运行时试图访问互联网连接。我得到的详细错误如下:-

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

我的 pom.xml 文件

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

我的 hibernate 配置(hibernate.cfg.xml)文件

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

我在其中创建 ConfigurationSession 对象的 HibernateUtil 类

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();
}
}
}

我想解决此问题,因为互联网连接并非始终可用。谢谢

最佳答案

要离线使用 hibernate,你必须在你的 xml 映射和配置文件中更改你的 dtd。确保 hibernate jar 在你的类路径中

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

配置文件:

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

关于java - 当没有互联网连接时,Hibernate 给出错误错误 "Access to DialectResolutionInfo cannot be null when ' hibernate.dialect' not set",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34416166/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com