Hibernate问题
一个库存主键类如下:
/** 库存主键 **/
@Embeddable
public class ProductStoragePk implements Serializable {
/** 样式编号 **/
private Integer styleid;
/** 尺码编号 **/
private Integer sizeid;
public ProductStoragePk(){}
public ProductStoragePk(Integer styleid,Integer sizeid){
this.styleid=styleid;
this.sizeid=sizeid;
}
@Column(name="styleid")
public Integer getStyleid() {
return styleid;
}
public void setStyleid(Integer styleid) {
this.styleid = styleid;
}
@Column(name="sizeid")
public Integer getSizeid() {
return sizeid;
}
public void setSizeid(Integer sizeid) {
this.sizeid = sizeid;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((sizeid == null) ? 0 : sizeid.hashCode());
result = prime * result + ((styleid == null) ? 0 : styleid.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final ProductStoragePk other = (ProductStoragePk) obj;
if (sizeid == null) {
if (other.sizeid != null)
return false;
} else if (!sizeid.equals(other.sizeid))
return false;
if (styleid == null) {
if (other.styleid != null)
return false;
} else if (!styleid.equals(other.styleid))
return false;
return true;
}
}
库存类:
/** 产品库存 **/
@Entity
public class ProductStorage implements Serializable {
/** 库存编号 **/
private ProductStoragePk storageid;
/** 库存量 **/
private Integer stocks=0;
/** 产品样式 **/
private ProductStyle style;
/** 产品尺码 **/
private ProductSize sizes;
public ProductStorage(){}
public ProductStorage(ProductStoragePk storageid){
this.storageid=storageid;
}
@EmbeddedId
public ProductStoragePk getStorageid() {
return storageid;
}
public void setStorageid(ProductStoragePk storageid) {
this.storageid = storageid;
}
@Column(nullable=false)
public Integer getStocks() {
return stocks;
}
public void setStocks(Integer stocks) {
this.stocks = stocks;
}
@ManyToOne(cascade=CascadeType.REFRESH,optional=false)
@JoinColumn(name="styleid",referencedColumnName="styleid")
public ProductStyle getStyle() {
return style;
}
public void setStyle(ProductStyle style) {
this.style = style;
}
@ManyToOne(cascade=CascadeType.REFRESH,optional=false)
@JoinColumn(name="size",referencedColumnName="sizeid")
public ProductSize getSizes() {
return sizes;
}
public void setSizes(ProductSize sizes) {
this.sizes = sizes;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((storageid == null) ? 0 : storageid.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final ProductStorage other = (ProductStorage) obj;
if (storageid == null) {
if (other.storageid != null)
return false;
} else if (!storageid.equals(other.storageid))
return false;
return true;
}
}
运行就报错:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'brandServiceBean': Injection of resource methods failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [beans.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Repeated column in mapping for entity: com.duoduo.bean.product.ProductStorage column: styleid (should be mapped with insert="false" update="false")