Hibernate问题

tangduoduo3333 2008-11-19 02:26:33
一个库存主键类如下:
/** 库存主键 **/
@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")
...全文
71 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
g3123298 2008-11-19
  • 打赏
  • 举报
回复
Error creating bean with name 'brandServiceBean': 【没有找到这个brandServiceBean


不晓得楼主是不是用applicationContext.xml 贴出来看看
在把hibernate.cfg.xml贴出来
后面的错误是没有创建sessionFactory



hashCode equals用的不少

67,538

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧