Currently mapping files get parsed and validated twice during JEE bootstrapping:
once in org.hibernate.ejb.Ejb3Configuration#addXMLEntities (from org.hibernate.ejb.Ejb3Configuration#configure, from org.hibernate.ejb.HibernatePersistence#createContainerEntityManagerFactory)
again to actually add it to the configuration from org.hibernate.ejb.Ejb3Configuration#addClassesToSessionFactory (from org.hibernate.ejb.Ejb3Configuration#configure, from org.hibernate.ejb.HibernatePersistence#createContainerEntityManagerFactory)
AFAICT, the first occurrence is used to identify classes for potential enhancement.
If I understand correctly, after the call to addXMLEntities we no longer really need the local List<String> xmlFiles variable for anything other than to pass it to (eventually) addClassesToSessionFactory so that they get added to the configuration. Seems to me the solution here is to save the parsed and validated DOM tree, once that code is fixed up ( see ), and pass that DOM tree into the config via a method that indicates it has already been validated.
Note : org.hibernate.cfg.AnnotationConfiguration#add(org.dom4j.Document) (3.5) / org.hibernate.cfg.Configuration#add(XmlDocument) (3.6) would be the right place I guess.
The only thing that rings a bell is that the code might use the file name for better error handling down the road but if you ahve not encountered that in the code path, that should be fine.
This is handled much differently on trunk. In 3.5 and prior eventually you always added a Document to the Configuration, which of course lost the ability to report on source file names. I improved that in 3.6 to use a custom XmlDocument instead that wraps the Document with some other information called an Origin.
So I'll roll this change back on the 3.5 branch.
rolling this back on 3.5 branch for error reporting concern