我无法解析hibernate.cfg.xml和geting
Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.hibernate.org/xsd/orm/cfg", local:"hibernate-configuration"). Expected elements are <{}hibernate-configuration>它可以使用xml解析器,就像它在引擎盖下使用stax一样。我们正在使用hibernate 5.2.3。我们的hibernate.cfg.xml文件的头是正确的,我尝试了两个Xsd
<?xml version="1.0" encoding='utf-8'?>
<hibernate-configuration
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<session-factory>和DTD
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>两者都有相同的错误。我一定是解析器的能手。
更新,我已经修复了问题代码,没有正确显示。我确信XML是有效的XML。
更新2我开始得到一些线索。这可能是由于将代码作为测试运行而导致的。特别是读取文件的com.sun.xml.internal.stream.XMLEventReaderImpl类,由MockClassLoader加载。
更新3他们通过驯服powermock来解决这里
@PowerMockIgnore({ "javax.xml.*", "org.xml.sax.*" })现在我有了不同的错误希望我在正确的轨道上。
java.lang.LinkageError: loader constraint violation: when resolving overridden method "com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(Lorg/w3c/dom/Node;)Ljava/lang/Object;" the class loader (instance of org/powermock/core/classloader/MockClassLoader) of the current class, com/sun/xml/internal/bind/v2/runtime/unmarshaller/UnmarshallerImpl, and its superclass loader (instance of <bootloader>), have different Class objects for the type org/w3c/dom/Node used in the signature属性中添加其他类来解析这里。
@PowerMockIgnore({ "javax.xml.*", "org.xml.sax.*", "com.sun.xml.*", "com.sun.org.*"})发布于 2021-08-10 17:52:05
使用java version "14.0.1"时,Hibernate 5.4.4会引发此错误。
意外元素(uri:"http://www.hibernate.org/xsd/orm/cfg",local:"hibernate-configuration")。
一个简单的降级,以java 8解决它。
正如在文档中提到的,Hibernate高达5.4.4。支持Java 8或11
https://stackoverflow.com/questions/47554697
复制相似问题