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

1.在写hibernate时,若运行出现"org.hibernate.InvalidMappingException: Could not parse mapping document from resource"问题,首先确定jar包导入无误;

2.接下来看 *.hbm.xml文件中的字段:

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

写了没(或写错了);

3.最后看 *.hbm.xml文件中格式是否有误,如设置值时,双引号中不能有多余字符,如空格等。

4.持久化类映射中出现了错误,

<hibernate-mapping>
<class name="com.test.session.User" table="t_user">
<id name="userid" type="string" column="idname">
    <generator class="uuid"/>

</id>
<property name="name"type="string"column="username"/>
<property name="password" type="string" column="userpw"/>
<property name="createdate" type="date"/>
<property name="expectdate" type="date"/>
</class>

</hibernate-mapping>

红色部分的class name一定要写正确,不然就找不到映射信息了,name="包名+类名" 而蓝色部的type则可以省略,因为在类文件中已经定义了表中属性的类型了!