日期:2014-05-18  浏览次数:20658 次

hibernate 映射文件无法解析的错误 求大神指导
Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/test/entity/hibernate.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:569)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
at com.test.contral.StudentTest.add(StudentTest.java:29)
at com.test.contral.StudentTest.main(StudentTest.java:20)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:508)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:566)
... 8 more
Caused by: org.dom4j.DocumentException: Error on line 3 of document  : The processing instruction target matching "[xX][mM][lL]" is not allowed. Nested exception: The processing instruction target matching "[xX][mM][lL]" is not allowed.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)

上面是错误代码


下面是hibernate.hbm.xml

<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="com.test.entity">
<class name="Student" table="student">
<id name="id" column="id" type="java.long.Integer">
<generator class="native"/>
</id>
<property name="name" column="name" type="java.long.String"></property>
<property name="age" column="age" type="java.long.Integer"></property>
</class>
</hibernate-mapping>


------解决方案--------------------
The processing instruction target matching "[xX][mM][lL]" is not allowed. Nested exception: The processing instruction target matching "[xX][mM][lL]" is not allowed.
------解决方案--------------------
检查下你的xml文件,是否开头有空格什么的,主要的错误就是这个xml解析过程中不符dtd。