欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

MyEclipse 使用hibernate反向工程工具出现org.hibernate.InvalidMappingException和 org.dom4j.DocumentException错误

程序员文章站 2022-03-02 13:49:42
...

今天使用MyEclipse 使用hibernate反向工程工具生成 类、映射文件和配置文件时碰到了这个问题
错误代码如下:

org.hibernate.InvalidMappingException: Unable to read XML
 at org.hibernate.util.xml.MappingReader.readMappingDocument(MappingReader.java:101)
 at org.hibernate.cfg.Configuration.add(Configuration.java:513)
 at org.hibernate.cfg.Configuration.add(Configuration.java:509)
 at org.hibernate.cfg.Configuration.add(Configuration.java:716)
 at org.hibernate.cfg.Configuration.addResource(Configuration.java:801)
 at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2344)
 at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2310)
 at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2290)
 at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2243)
 at org.hibernate.cfg.Configuration.configure(Configuration.java:2158)
 at dao.HibernateUtil.<clinit>(HibernateUtil.java:18)
 at dao.BaseDao.currentSession(BaseDao.java:9)
 at service.DeptBiz.getAllDept(DeptBiz.java:22)
 at test.DeptTest.test(DeptTest.java:17)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
 at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
 at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
 at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
 at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
 at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
 at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
 at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
 at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
 at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
 at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.dom4j.DocumentException: http://hibernate.org/dtd/hibernate-mapping-3.0.dtd%20 Nested exception: http://hibernate.org/dtd/hibernate-mapping-3.0.dtd%20
 at org.dom4j.io.SAXReader.read(SAXReader.java:484)
 at org.hibernate.util.xml.MappingReader.readMappingDocument(MappingReader.java:75)
 ... 36 more

问题原因是: 类映射文件的头部声明部分
错误代码:

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd "> 

代码更改为:

<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

原因:可能是与dom4j 的jar文件的头部声明 起冲突.

记录下错误信息