The markup declarations contained or pointed to by the document type declaration must be well-formed

@Ludo for now, we are trying to understand what the problem is exactly. If it’s an issue with the redirection, HTTPS or a combination of both.

Yoann was unable to reproduce this locally with various JDKs so we still don’t know what the problem is exactly.
If you put the www. URLs in a browser, you will see they work properly. So there’s something in your (and others) Java stack that doesn’t support this setup.
We want to understand exactly what.

In what you pasted, your first sample has www.hibernate.org. It shouldn’t have the www. Make sure you use for both files the URL I pasted.

Also you confirm that this wasn’t a transient issue, you still have the problem if you are using www?

1 Like

Thanks for your answer :slight_smile:
So you right I did a mistake in the URL so I have replaced by the one you gave me:

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

But I still have the same error at startup:

2022-02-24 17:33:38.447 INFO  Configuration:497 - Reading mappings from resource: XXXX.hbm.xml
2022-02-24 17:33:39.694 ERROR YYYYY:52 - server error org.hibernate.MappingException: Could not read mappings from resource: XXXX.hbm.xml

If I go in my web browser I can download the file without any issue and it seems the be the exact same as the one of sourceforge.net
I don’t know if we would have the same error message is my application was not able to reach this URL (for what ever reason).

So I tried also with a wrong URL (toto.org)

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

And the error message is the same:

2022-02-24 17:40:19.442 INFO  Configuration:497 - Reading mappings from resource: XXXX.hbm.xml
2022-02-24 17:40:20.601 ERROR YYYY:52 - server error org.hibernate.MappingException: Could not read mappings from resource: XXXX.hbm.xml

To keep in mind In case of the original URL

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

The error message is this one:

2022-02-24 17:42:31.684 INFO  Configuration:497 - Reading mappings from resource: XXXX.hbm.xml
2022-02-24 17:42:32.605 ERROR XMLHelper:61 - Error parsing XML: XML InputStream(1) The markup declarations contained or pointed to by the document type declaration must be well-formed.
2022-02-24 17:42:32.609 ERROR YYYYY:52 - server error org.hibernate.MappingException: Could not read mappings from resource: XXXX.hbm.xml

@Ludo so it looks like it’s HTTPS that is the issue.

Two things:

  • could you give us the exact version of OpenJDK 8 and Corretto 11 you are using?
  • could you send us the list of dependencies + version for each (ideally, if you’re using Maven, the output of mvn dependency:tree). You can send it to gsmet and yrodiere, both at redhat dot com as I suspect it might contain things that you might not want to share publicly.

Thanks a lot!

What worked for us is → “https://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd

java.lang.RuntimeException: org.xml.sax.SAXParseExceptionpublicId: -//Hibernate/Hibernate Mapping DTD 3.0//EN; systemId: http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd; lineNumber: 1; columnNumber: 3; The markup declarations contained or pointed to by the document type declaration must be well-formed.
at org.hibernate.tool.hbm2x.XMLPrettyPrinter.prettyFormat(XMLPrettyPrinter.java:40)
at org.hibernate.tool.hbm2x.XMLPrettyPrinter.prettyPrintFile(XMLPrettyPrinter.java:24)
at org.hibernate.tool.hbm2x.ArtifactCollector.formatXml(ArtifactCollector.java:69)
at org.hibernate.tool.hbm2x.ArtifactCollector.formatFiles(ArtifactCollector.java:58)
at org.hibernate.tool.hbm2x.AbstractExporter.start(AbstractExporter.java:102)
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 org.jboss.tools.hibernate.runtime.common.Util.invokeMethod(Util.java:43)
at org.jboss.tools.hibernate.runtime.common.AbstractExporterFacade.start(AbstractExporterFacade.java:72)
at org.hibernate.eclipse.console.common.ConsoleExtension$1.execute(ConsoleExtension.java:219)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:63)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:107)
at org.hibernate.eclipse.console.common.ConsoleExtension.runExporters(ConsoleExtension.java:182)
at org.hibernate.eclipse.console.common.ConsoleExtension.launchExporters(ConsoleExtension.java:110)
at org.hibernate.eclipse.launch.CodeGenerationLaunchDelegate.launch(CodeGenerationLaunchDelegate.java:266)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:860)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:719)
at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1017)
at org.eclipse.debug.internal.ui.DebugUIPlugin$2.run(DebugUIPlugin.java:1220)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: org.xml.sax.SAXParseExceptionpublicId: -//Hibernate/Hibernate Mapping DTD 3.0//EN; systemId: http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd; lineNumber: 1; columnNumber: 3; The markup declarations contained or pointed to by the document type declaration must be well-formed.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at org.hibernate.tool.hbm2x.xml.AbstractXMLPrettyPrinterStrategy.newDocument(AbstractXMLPrettyPrinterStrategy.java:23)
at org.hibernate.tool.hbm2x.xml.TrAXPrettyPrinterStrategy.prettyPrint(TrAXPrettyPrinterStrategy.java:20)
at org.hibernate.tool.hbm2x.XMLPrettyPrinter.prettyFormat(XMLPrettyPrinter.java:38)
… 21 more

@yrodiere while trying to build hbm file getting error like this. Do you have any suggestions to update in hibernate.cfg.xml or in hibernate.reveng.xml file…?

Thanks @Ludo for providing us with extensive information about your dependencies.

In short, to be safe:

  • As a rule, you should use a URL without redirection for your DTD, e.g. https://hibernate.org/dtd/hibernate-configuration-3.0.dtd or https://hibernate.org/dtd/hibernate-mapping-3.0.dtd. This will, however, lead to downloading the DTD from the internet on startup, except on very recent versions of Hibernate ORM (HHH-15094).
  • If you use a reasonably recent version of Hibernate ORM (4+) and do not use hbm2java, then you can use http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd/http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd safely (it won’t be downloaded from the internet).

Explanation follows.

The problem is caused by Xerces parsing the comment at the start of the DTD file incorrectly, but only when there is an HTTP redirection to get the DTD, and the redirected URL uses HTTPS. Don’t ask me why, I gave up on understanding the code of Xerces.

On new versions of Hibernate ORM (4+, I think?), we have a thing called LocalXmlResourceResolver which will skip the download of the DTD when you use a known DTD URL in your XML file. http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd is one of the recognized URLs, so that URL will always work fine on ORM 4+, even if the server goes down or adds problematic HTTP redirections.

However, if you use another DTD URL that is not recognized by LocalXmlResourceResolver (including https://hibernate.org/dtd/hibernate-mapping-3.0.dtd), then Xerces will attempt to download the DTD, and in case there is a redirection to HTTPS, it will fail miserably.

As to hbm2java, I suspect it doesn’t use LocalXmlResourceResolver and thus is affected by the Xerces bug regardless of the DTD URL (as soon as there’s a redirection, it will fail).

I created a ticket on Hibernate ORM to support more URLs in LocalXmlResourceResolver, in particular HTTPS URLs: [HHH-15094] - Hibernate JIRA

I also created a ticket on Hibernate Tools to make use of LocalXmlResourceResolver: [HBX-2307] - Hibernate JIRA

Once those two tickets are fixed, on recent Hibernate ORM or Hibernate Tools versions, the solution will become "use whatever hibernate.org URL you want, it will just use a local file.

Also, for future reference: I reproduced the DTD redirection bug on the following branch: GitHub - yrodiere/hibernate-test-case-templates at dtd-redirection-reproducer

2 Likes

IT just reverted the changes to the redirection: http://www.hibernate.org/dtd/* once again redirects to http://hibernate.org/dtd/*, instead of https://hibernate.org/dtd/*. So the Xerces bug should not be triggered anymore.

To anybody reading this, be aware that we will eventually phase out HTTP and put redirections to HTTPS everywhere. Thus, I advise you to follow the suggestion in the post just above.

2 Likes