离线时无法分析hibernate.cfg.xml [英] Can't parse hibernate.cfg.xml while offline
问题描述
org.hibernate.HibernateException:Could not解析配置:com / mashlife / resources / hibernate.cfg.xml $ b $ org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1542)
org.hibernate.cfg.AnnotationConfiguration.doConfigure( AnnotationConfiguration.java:1035)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:64)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
在org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:1017)
引起:org.dom4j.DocumentException:www.hibernate.org嵌套异常:www.hibernate.org
在org.dom4j.io.SAXReader.read(SAXReader.java:484)
在org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1532)
... 45更多
仅限 当我离线时发生。在解析配置时,hibernate是否尝试读取DTD?这里的根本原因是什么?
这是我的hibernate.cfg.xml:
<?xml version ='1.0'encoding ='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
- // Hibernate / Hibernate配置DTD 3.0 // EN
http://www.hibernate.org/dtd/hibernate-configuration -3.0.dtd>
< hibernate-configuration>
< session-factory>
<! - 数据库连接设置 - >
< property name =connection.driver_class> com.mysql.jdbc.Driver< / property>
< property name =connection.url> jdbc:mysql:// localhost / foo< / property>
< property name =connection.username> user< / property>
< property name =connection.password> pass< / property>
<! - JDBC连接池(使用内置) - >
< property name =connection.pool_size> 1< / property>
<! - - SQL方言 - >
< property name =dialect> org.hibernate.dialect.MySQLInnoDBDialect< / property>
<! - 禁用二级缓存 - >
< property name =cache.provider_class> org.hibernate.cache.NoCacheProvider< / property>
<! - 不要将所有执行的SQL回复到stdout - >
< property name =show_sql> false< / property>
<! - 给注释的实体类命名 - >
<! - < mapping class =org.hibernate.tutorial.annotations.Event/> - >
< / session-factory>
< / hibernate-configuration>
Hibernate可以本地解析DTD(无需网络连接)。
您的DOCTYPE正在使用新的命名空间( http ://www.hibernate.org/dtd/ ),因此您的类路径中可能会包含旧版Hibernate库。
升级到Hibernate 3.6.8.Final后,我遇到了同样的问题。我在类路径中有多个hibernate3.jar版本,导致旧版本的 DTD Entity Resolver 将被加载,它只适用于旧的命名空间( http://hibernate.sourceforge.net/ )。作为参考,这里是一个链接到新的 DTD Entity Resolver 。
我使用hibernate3-maven-plugin,它对旧版本的Hibernate所以我只需要在Hibernate 3.6.8.Final中指定一个插件依赖项。
< plugin>
< groupId> org.codehaus.mojo< / groupId>
< artifactId> hibernate3-maven-plugin< / artifactId>
< version> 2.2< / version>
<配置>
...
< / configuration>
<依赖关系>
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-core< / artifactId>
< version> 3.6.8.Final< / version>
< /依赖关系>
< /依赖关系>
< / plugin>
Whenever I'm disconnected from the internet, I get the following exception:
org.hibernate.HibernateException: Could not parse configuration: com/mashlife/resources/hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1542)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:1035)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:64)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:1017)
Caused by: org.dom4j.DocumentException: www.hibernate.org Nested exception: www.hibernate.org
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1532)
... 45 more
This only happens when I'm offline. Does hibernate try to read the DTD when parsing the config? What's the root cause here?
Here is my hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/foo</property>
<property name="connection.username">user</property>
<property name="connection.password">pass</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- DO NOT Echo all executed SQL to stdout -->
<property name="show_sql">false</property>
<!-- Names the annotated entity class -->
<!--<mapping class="org.hibernate.tutorial.annotations.Event"/>-->
</session-factory>
</hibernate-configuration>
Hibernate can resolve the DTDs locally (without a network connection).
Your DOCTYPE is using the new namespace (http://www.hibernate.org/dtd/) for Hibernate 3.6, so you might have an older version of the Hibernate libraries in your classpath.
I experienced the same issue after upgrading to Hibernate 3.6.8.Final. I had multiple versions of hibernate3.jar on the classpath causing an old incompatible version of the DTD Entity Resolver to be loaded which only works with the old namespace (http://hibernate.sourceforge.net/). For reference, here's a link to the newer DTD Entity Resolver.
I'm using hibernate3-maven-plugin which has a transitive dependency on an older version of Hibernate so I just had to specify a plugin dependency on Hibernate 3.6.8.Final.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
...
</configuration>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.8.Final</version>
</dependency>
</dependencies>
</plugin>
这篇关于离线时无法分析hibernate.cfg.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!