我正在两个班级OneToOne
和SkuImpl
之间建立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")
如何解决这种异常?
答案 0 :(得分:0)
尝试像这样写@JoinColumn
:
@OneToOne(optional=true,targetEntity=SkuImpl.class,cascade=CascadeType.ALL)
@JoinColumn(name="SKU_ID",referencedColumnName="someNameOfColumnId")
protected Sku sku;
referencedColumnName
是SkuImpl
类中的列ID。
下面的代码是不必要的:
@OneToOne(targetEntity=SkuAvailabilityImpl.class)
protected SkuAvailability totalSku;