hibernate-Could not parse mapping document from resource

问题描述

Could not parse mapping document from resource

Employee.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">

    <property name="name"/>
    <property name="sex"/>
    <property name="age"/>

</class>

hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- 数据库连接设置 -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/renli</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>

<!-- 数据库方言设置 sql方言 -->
<property name="dialect">org.hibernate.dialect.DerbyDialect</property>

<!-- 显示sql语句 -->
<property name="show_sql">true</property>
<!-- 格式化sql语句(换行) -->
<property name="format_sql">true</property>

<!-- 启动hibernate时,引用旧有的数据库表格(create是建立新表,相当于重置数据库数据) -->
<property name="hbm2ddl.auto">update</property>

<!-- 配置映射文件 -->
<mapping resource="www/sail/domain/Employee.hbm.xml" />

错误信息

org.hibernate.InvalidMappingException: Could not parse mapping document from resource www/sail/domain/Employee.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:616)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1635)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
at www.sail.domain.EmployeeTest.before(EmployeeTest.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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.RunBefores.evaluate(RunBefores.java:27)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
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:49)
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.hibernate.MappingException: class Employee.java not found while looking for property: id
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:232)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:302)
at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:423)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:356)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:295)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:166)
at org.hibernate.cfg.Configuration.add(Configuration.java:716)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:551)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:613)
... 29 more
Caused by: java.lang.ClassNotFoundException: Employee.java
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:228)
... 37 more

解决方案

配置文件无法解析
http://zhidao.baidu.com/link?url=Spq4HanCf6dcXRUBQlN2VlDCk673MUdZXDmPW0DnSLpMBka0imVJr0rNN3NWacLcVBOtqKC9mcseSkaHl8UsOq

解决方案二:

http://www.iteye.com/problems/10561

时间: 2024-11-18 17:25:45

hibernate-Could not parse mapping document from resource的相关文章

org.hibernate.InvalidMappingException: Could not parse mapping document from

问题描述 照网上方法,试了很多,但仍解决不了.=========================================================================================================12:01:14,672  INFO Version:37 - HCANN000001: Hibernate Commons Annotations {4.0.1.Final}12:01:14,721  INFO Version:41 - HH

Could not parse mapping document from input stream

问题描述 严重:Exceptionsendingcontextinitializedeventtolistenerinstanceofclassorg.springframework.web.context.ContextLoaderListenerorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'sessionFactory'definedinclasspathresource[a

MySQL错误(org.hibernate.MappingException: No Dialect mapping for JDBC type: -4) 解决方案

今天将开发完毕的项目发布到服务器上有,出现如下错误: org.hibernate.MappingException: No Dialect mapping for JDBC type: -4 后经过分析,是因为服务器上的mysql版本较低(为5.1.66),本地开发版本为5.5的则没有这个问题,下面直接贴出解决方法: 1.增加Java类 import java.sql.Types; import org.hibernate.Hibernate; import org.hibernate.dial

hibernate 日志异常

问题描述 最近学习hibernate,看书感觉可以,实际操作怎么就那么难呢!我用的是:hibernate3.2 eclipse3.3 (没有Myeclipse插件) Mysql6.0一:main()函数 package org.first;import org.hibernate.*;import org.hibernate.cfg.*;public abstract class FirstM {/** * @param args */public static void main(String

刚刚学习hibernate,出了点错,大神能帮我看看吗?

问题描述 刚刚学习hibernate,出了点错,大神能帮我看看吗? org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.component.PojoComponentTuplizer] at org.hibernate.tuple.component.ComponentTuplizerFactory.constructTuplizer(ComponentTupl

Hibernate 异常找不到持久化类的配置文件,郁闷!

问题描述 hibernate 配置文件如下:<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><

Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister报错解决办法

初学Hibernate 框架,在练习数据库的关联关系映射实验测试中出现了Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister错误. 由此引出的的错误提示: Could not parse mapping document from resource org/vo/Hibernatemapping.hbm.xml.在看到报错时首先检查了get 和set方法 ,发现没有漏写. 接

initialization-启动tomcat报错:好像是hbm.xml的问题

问题描述 启动tomcat报错:好像是hbm.xml的问题 10:19:25,238 ERROR ContextLoader:215 - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'deparrtmentDaoImpl': Injection of resource fields failed; neste

项目启动时报错Element type "property" must be followed by either attri

项目启动时报错Element type "property" must be followed by either attribute specifications, ">" or "/>" 项目启动时,控制台报错,信息如下(有删减): Error creating bean with name 'supplierInfoDAO' defined in class path resource [conf/applicationCont