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