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則可以省略,因爲在類文件中已經定義了表中屬性的類型了!