无法解析hibernate.cfg.xml [英] Unable to parse hibernate.cfg.xml
问题描述
我无法解析hibernate.cfg.xml并获取
I'm unable to parse hibernate.cfg.xml and 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一样.我们正在休眠5.2.3.我的hibernate.cfg.xml文件的标题正确,我都尝试了Xsd
It can be something with xml parser, it seams like it uses stax under the hood. We are on hibernate 5.2.3. The header of our hibernate.cfg.xml file is correct I tried both 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>
两者都有相同的错误.我一定对解析器有所了解.
Both have the same error. I must be something with the parser.
更新 我已经修复了问题代码不正确可见的问题.我确定XML是有效的XML.
UPDATE I have fixed the question code was not properly visible. I'm sure the XML is valid XML.
更新2
我开始得到一些线索.这可能是由于将代码作为junit powermock测试运行而引起的.具体来说,读取文件的com.sun.xml.internal.stream.XMLEventReaderImpl
类是由MockClassLoader加载的.
UPDATE 2
I start to get some clues. It can be caused by running the code as junit powermock test. Specifically com.sun.xml.internal.stream.XMLEventReaderImpl
class reading the file, is loaded by MockClassLoader.
更新3 他们在在这里解决了这个问题,方法是将powermock驯服一点b
UPDATE 3 They solved it here by taming powermock a little b
@PowerMockIgnore({ "javax.xml.*", "org.xml.sax.*" })
现在我有不同的错误希望我走在正确的轨道上.
Now I have different error hope I'm on the right track.
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
此处已解决,方法是将其他类添加到
That is resolved here by adding additional classes to the
@PowerMockIgnore({ "javax.xml.*", "org.xml.sax.*", "com.sun.xml.*", "com.sun.org.*"})
推荐答案
您是否可以尝试为hibernate.cfg.xml文件更改并使用此模板:
can you try to change and use this template for hibernate.cfg.xml file:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="domain">
<property name="hibernate.show_sql">false</property>
<mapping package="com.example.dao.entity"/>
<!-- etc -->
</session-factory>
</hibernate-configuration>
这篇关于无法解析hibernate.cfg.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!