org.hibernate.MappingException:OneToOne Mapping实体映射中的重复列

时间:2016-03-19 08:39:38

标签: java hibernate

我正在两个班级OneToOneSkuImpl之间建立SkuAvailability关系。下面是那个

的代码

SkuImpl.java

@Entity 
public class SkuImpl implements  Sku {
    @OneToOne(targetEntity=SkuAvailabilityImpl.class) 
    protected SkuAvailability totalSku;
    //setter and getters
}

SkuAvailabilityImpl.java

@Entity 
public class SkuAvailabilityImpl implements SkuAvailability{
    @OneToOne(optional=true,targetEntity=SkuImpl.class,cascade=CascadeType.ALL) 
    @JoinColumn(name="SKU_ID")
    protected Sku sku;
    //setter and getters
}

当我尝试将应用程序部署到glassfish时,它没有部署,得到例外

Caused by: org.hibernate.MappingException: Repeated column in mapping for entity:
SkuAvailabilityImpl column: SKU_ID
(should be mapped with insert="false" update="false")

如何解决这种异常?

1 个答案:

答案 0 :(得分:0)

尝试像这样写@JoinColumn

@OneToOne(optional=true,targetEntity=SkuImpl.class,cascade=CascadeType.ALL) 
@JoinColumn(name="SKU_ID",referencedColumnName="someNameOfColumnId")
protected Sku sku;

referencedColumnNameSkuImpl类中的列ID。

下面的代码是不必要的:

  @OneToOne(targetEntity=SkuAvailabilityImpl.class) 
  protected SkuAvailability totalSku;