Hi,
When I startup my Glassfish server and load hibernate it takes a very long time to load the .hbm.xml mapping files.
I profiled this:
Code:
34,5% - 22.819 ms - 196 inv. org.dom4j.io.SAXReader.read(org.xml.sax.InputSource)
32,8% - 21.686 ms - 196 inv. org.hibernate.cfg.EJB3DTDEntityResolver.resolveEntity
32,8% - 21.685 ms - 196 inv. org.hibernate.internal.util.xml.DTDEntityResolver.resolveEntity
32,8% - 21.670 ms - 196 inv. org.hibernate.internal.util.xml.DTDEntityResolver.resolveInLocalNamespace
32,8% - 21.670 ms - 196 inv. org.hibernate.internal.util.ConfigHelper.getUserResourceAsStream
32,8% - 21.669 ms - 196 inv. java.lang.ClassLoader.getResourceAsStream
And as you see the problem seems to be in the DTD resolver. The first time it is called it scans the whole classpath (including glassfish) and it takes 21 seconds to do this. This delay is only noticeable the first hbm.xml mapping file is loaded. All DTD's after the first one resolv in less than 2 ms.
All my hbm.xml files have the following DTD's:
Code:
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
I had a look at the source code of the entity resolver:
Code:
public InputSource resolveEntity(String publicId, String systemId) {
InputSource source = null;
if(systemId != null) {
...
if(systemId.startsWith("http://www.hibernate.org/dtd/")) {
...
source = this.resolveOnClassPath(publicId, systemId, "http://www.hibernate.org/dtd/");
} else if(systemId.startsWith("http://hibernate.sourceforge.net/")) {
..
source = this.resolveOnClassPath(publicId, systemId, "http://hibernate.sourceforge.net/");
} else if(systemId.startsWith("classpath://")) {
And tried www.hibernate.org as well as classpatj:// but they all scan the whole classpath.
The DTD is located in the hibernate JAR and it works perfectly but it is just slow.
Is there any way I can speed this up?
Additional information:
Hibernate version: 4.1.7
Glassfish: 3.1.2.2
Thanks for having a look!