1、异常描述
Caused by: org.hibernate.MappingException:
Repeated column in mapping for entity: cn.wang.entity.Student column:
cid (should be mapped with insert="false" update="false")
备注:
此处hibernate版本号:3.6.10.Final
2、示例代码
2-1 实体类
// 班级实体类
public class Clazz implements Serializable{
private Integer id;
private String name;
// 省略部分代码....
}
// 学生实体类
public class Student implements Serializable{
private Integer id;
private String name;
private Date birthday;
private Integer cid;// 外键列
// 创建关系属性
private Clazz clazz;
// 关系属性set/get
public Clazz getClazz() {
return clazz;
}
public void setClazz(Clazz clazz) {
this.clazz = clazz;
}
// 省略部分代码....
}

博客详细介绍了在使用Hibernate时遇到的MappingException异常,问题在于实体类Student的hbm.xml文件中,外键cid被重复映射。解决方案是删除<property>标签中关于cid的映射,避免在实体类中重复映射外键列。通过这种方法可以解决Hibernate映射冲突的问题。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



