InvalidMappingException提示Could not parse mapping document错误的解决方法

转自:http://www.itzhai.com/invalidmappingexception-could-not-parse-mapping-document-prompt-the-wrong-solution.html

org.hibernate.InvalidMappingException: Could not parse mapping document from resource …(错误的xml文件)

出现这样的错误一般是映射文件中映射出错了,找到错误提示resource 后面提示的xml文件,对应POJO对象逐个检查,看是否遗漏了某些属性的配置,或者写错了。

举个例子:
package com.exam.entity;
import java.util.Set;
public class SubjectChapter {
	private int chapterId;
	private String chapterName;
	private Subject subject;
	private int chapterNum;
	private Set question;
	public int getChapterId() {
		return chapterId;
	}
	public void setChapterId(int chapterId) {
		this.chapterId = chapterId;
	}
	public String getChapterName() {
		return chapterName;
	}
	public void setChapterName(String chapterName) {
		this.chapterName = chapterName;
	}
	public Subject getSubject() {
		return subject;
	}
	public void setSubject(Subject subject) {
		this.subject = subject;
	}
	public int getChapterNum() {
		return chapterNum;
	}
	public void setChapterNum(int chapterNum) {
		this.chapterNum = chapterNum;
	}
	public Set getQuestion() {
		return question;
	}
	public void setQuestion(Set question) {
		this.question = question;
	}
}
<hibernate-mapping package="com.exam.entity">
	<class name="SubjectChapter" table="exam_subject_chapter">
		<id name="chapterId" column="chapter_id">
			<generator class="increment" />
		</id>
		<property name="chapterName" column="chapter_name"/>
		<many-to-one name="subject" column="subject_id" cascade="all"/>
		<property name="chapterNum" column="chapter_num"/>
		<set name="question" inverse="true">
			<key column="subject_chapter_id"/>
			<one-to-many class="Question"/>
		</set>

	</class>
</hibernate-mapping>

这里原本少写了chapterNum的映射,导致该错误的出现。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值