当它试图在本地加载persistence.xml
时,这实际上与Hibernate有关。
Here is the stacktrace and error
ERROR javax.persistence.PersistenceException: Invalid persistence.xml.
Error parsing XML (line-1 : column -1): cvc-elt.1.a: Cannot find the declaration of element 'HTML'.
at org.hibernate.ejb.packaging.PersistenceXmlLoader.loadURL(PersistenceXmlLoader.java:145)
at org.hibernate.ejb.packaging.PersistenceXmlLoader.deploy(PersistenceXmlLoader.java:169)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:317)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
实际上持久性xml是简单的(我把它从较大的那个最小化,因为它没有区别)
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
</persistence>
问题在于文档构建器中的这一行
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
docBuilder.setEntityResolver(resolver);
doc = docBuilder.parse(source);
>The doc after parsed has HTML tags in it which it should not because its just a xml. I traveresed the nodes in the doc and got below elements
Found element HTML
Found element HEAD
Found element BODY
Found element PERSISTENCE
这就是为什么XSD架构验证失败,因为它不期望html元素。
任何人都知道为什么以及如何克服这一点。
发现了这个问题。我在类路径中有nekohtml-1.9.22.jar。它是一个解析器,也是一个标记平衡器。它被当作默认的解析器,因为它没有在xml中找到HTML标签,所以它添加了它。奇怪的是它不应该是XML的默认值。无论如何从类路径中删除它解决了这个问题。