Hibernate 3.5 抛出“org.dom4j.DocumentException:文档 http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd 第 1 行错误”

发布于 2025-01-10 06:06:28 字数 1395 浏览 0 评论 0原文

我的 Hypersistence Optimizer 代码库中有一些 Hibernate 3.5 测试,现在我收到了这个奇怪的错误:

org.hibernate.InvalidMappingException: Could not parse mapping document from resource hbm/mapping/association/EagerFetchingManyToOneFetchJoinHbmTest.hbm.xml

    at org.hibernate.cfg.Configuration.addResource(Configuration.java:671)
    at io.hypersistence.optimizer.util.AbstractHypersistenceOptimizerTest.newSessionFactory(AbstractHypersistenceOptimizerTest.java:108)
    at io.hypersistence.optimizer.util.AbstractHypersistenceOptimizerTest.init(AbstractHypersistenceOptimizerTest.java:63)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream
    at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:610)
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:668)
    ... 25 more
Caused by: org.dom4j.DocumentException: Error on line 1 of document http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd : The markup declarations contained or pointed to by the document type declaration must be well-formed. Nested exception: The markup declarations contained or pointed to by the document type declaration must be well-formed.
    at org.dom4j.io.SAXReader.read(SAXReader.java:482)
    at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:601)
    ... 26 more

所有这些测试都运行良好 3 年,所以这可能是最近发生的更改。

I have some Hibernate 3.5 tests in my Hypersistence Optimizer code base, and I'm now getting this weird error:

org.hibernate.InvalidMappingException: Could not parse mapping document from resource hbm/mapping/association/EagerFetchingManyToOneFetchJoinHbmTest.hbm.xml

    at org.hibernate.cfg.Configuration.addResource(Configuration.java:671)
    at io.hypersistence.optimizer.util.AbstractHypersistenceOptimizerTest.newSessionFactory(AbstractHypersistenceOptimizerTest.java:108)
    at io.hypersistence.optimizer.util.AbstractHypersistenceOptimizerTest.init(AbstractHypersistenceOptimizerTest.java:63)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream
    at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:610)
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:668)
    ... 25 more
Caused by: org.dom4j.DocumentException: Error on line 1 of document http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd : The markup declarations contained or pointed to by the document type declaration must be well-formed. Nested exception: The markup declarations contained or pointed to by the document type declaration must be well-formed.
    at org.dom4j.io.SAXReader.read(SAXReader.java:482)
    at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:601)
    ... 26 more

All these tests ran just fine for 3 years, so this may be a change that happened lately.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

≈。彩虹 2025-01-17 06:06:28

该问题是由最近在 hibernate.org 网站上设置的 HTTP->HTTPS 重定向引起的:

~# wget http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd
--2022-02-25 20:53:22--  http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd
Resolving www.hibernate.org (www.hibernate.org)... 34.235.198.240, 52.200.142.250
Connecting to www.hibernate.org (www.hibernate.org)|34.235.198.240|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://hibernate.org/dtd/hibernate-mapping-3.0.dtd [following]
--2022-02-25 20:53:22--  https://hibernate.org/dtd/hibernate-mapping-3.0.dtd
Resolving hibernate.org (hibernate.org)... 185.199.111.153, 185.199.110.153, 185.199.108.153, ...
Connecting to hibernate.org (hibernate.org)|185.199.111.153|:443... connected.

问题在于 Hibernate 3.5 无法正确处理此问题。

所以,解决方案非常简单。

将 HBM​​ 文件开头的 DTD DOCTYPE 定义从: 更改

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

为:

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

The problem is caused by an HTTP->HTTPS redirect that was set lately on the hibernate.org website:

~# wget http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd
--2022-02-25 20:53:22--  http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd
Resolving www.hibernate.org (www.hibernate.org)... 34.235.198.240, 52.200.142.250
Connecting to www.hibernate.org (www.hibernate.org)|34.235.198.240|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://hibernate.org/dtd/hibernate-mapping-3.0.dtd [following]
--2022-02-25 20:53:22--  https://hibernate.org/dtd/hibernate-mapping-3.0.dtd
Resolving hibernate.org (hibernate.org)... 185.199.111.153, 185.199.110.153, 185.199.108.153, ...
Connecting to hibernate.org (hibernate.org)|185.199.111.153|:443... connected.

The problem is that Hibernate 3.5 doesn't handle this properly.

So, the solution is very simple.

Change the DTD DOCTYPE definition at the beginning of your HBM files from:

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

to:

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文