Repeated column in mapping for entity: cn.itcast.shop.review.Review column: pid (should be mapped wi

今天开发ssh项目遇到如下bug,下面贴出解决方案:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Repeated column in mapping for entity: cn.itcast.shop.review.Review column: pid (should be mapped with insert="false" update="false")

看一下代码:我在review类中加了个pid字段,pid是商品表product的主键,他作为review评论表的外键


public class Review {
    private Integer reviewid;
    private  String re_name;
    private String re_content;
    private String re_time;
    private Integer pid;
     public Integer getPid() {
        return pid;
    }
    public void setPid(Integer pid) {
        this.pid = pid;
    }
    //所属的商品类】
     private Product product;
    public Integer getReviewid() {
        return reviewid;
    }
    public void setReviewid(Integer reviewid) {
        this.reviewid = reviewid;
    }
    public String getRe_name() {
        return re_name;
    }
    public void setRe_name(String re_name) {
        this.re_name = re_name;
    }
    public String getRe_content() {
        return re_content;
    }
    public void setRe_content(String re_content) {
        this.re_content = re_content;
    }
    public String getRe_time() {
        return re_time;
    }
    public void setRe_time(String re_time) {
        this.re_time = re_time;
    }
    
    public Product getProduct() {
        return product;
    }
    public void setProduct(Product product) {
        this.product = product;
    }
    
}
错误就在于这个外键,外键pid是不需要重新再实体类中声明,因为在review.hbm.xml文件中我已经定义,如下:

        <many-to-one name="product" class="cn.itcast.shop.product.Product" column="pid"></many-to-one>

这个many-to-one已经声明了外键,所以报错他会说repeated column(重复字段)

解决办法:

去掉所有外键的配置只保留many-to-one的那个!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值