其实也就几句话
goods关联了product 是一对多的关系
我更改了goods里面的product的信息
controller类代码
this.goodsService.update(goods);
serviceImpl类代码:
Goods good = (Goods)super.update(goods);
update调用的是下面DaoImpl来实现的
DaoImpl代码是调用的:
this.session.merge(goods);
merge的时候应该才报的这个问题
实体类
@Entity
@Table(name=”goods”)
public class Goods extends BaseEntity
{
private static final long serialVersionUID = -6977025562650112419L;
private Set<Product> products = new HashSet<Product>();
@OneToMany(mappedBy=”goods”, fetch=FetchType.EAGER, cascade={javax.persistence.CascadeType.ALL}, orphanRemoval=true)
public Set<Product> getProducts()
{
return this.products;
}
@Entity
@Table(name=”product”)
public class Product extends BaseEntity{
private Goods good;
private List<ProductImage> productImages = new ArrayList();
private Set<Review> reviews = new HashSet();
private Set<Consultation> consultations = new HashSet();
private Set<Tag> tags = new HashSet();
private Set<Member> favoriteMembers = new HashSet();
private Set<Specification> specifications = new HashSet();
private Set<SpecificationValue> specificationValues = new HashSet();
private Set<Promotion> promotions = new HashSet();
private Set<CartItem> cartItems = new HashSet();
private Set<OrderItem> orderItems = new HashSet();
private Set<GiftItem> giftItems = new HashSet();
private Set<ProductNotify> productNotifies = new HashSet();
private Map<MemberRank, BigDecimal> memberPrice = new HashMap();
private Map<Parameter, String> parameterValue = new HashMap();
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(nullable=false, updatable=false)
public Goods getGoods()
{
return this.good;
}
public void setGoods(Goods goods)
{
this.good = goods;
}
@Valid
@ElementCollection
@CollectionTable(name=”product_product_image”)
public List<ProductImage> getProductImages()
{
return this.productImages;
}
public void setProductImages(List<ProductImage> productImages)
{
this.productImages = productImages;
}
@OneToMany(mappedBy=”product”, fetch=FetchType.LAZY, cascade={javax.persistence.CascadeType.REMOVE})
public Set<Review> getReviews()
{
return this.reviews;
}
public void setReviews(Set<Review> reviews)
{
this.reviews = reviews;
}
@OneToMany(mappedBy=”product”, fetch=FetchType.LAZY, cascade={javax.persistence.CascadeType.REMOVE})
public Set<Consultation> getConsultations()
{
return this.consultations;
}
public void setConsultations(Set<Consultation> consultations)
{
this.consultations = consultations;
}
@ManyToMany(fetch=FetchType.LAZY)
@JoinTable(name=”product_tag”)
@OrderBy(“order asc”)
public Set<Tag> getTags()
{
return this.tags;
}
public void setTags(Set<Tag> tags)
{
this.tags = tags;
}
@ManyToMany(mappedBy=”favoriteProducts”, fetch=FetchType.LAZY)
public Set<Member> getFavoriteMembers()
{
return this.favoriteMembers;
}
public void setFavoriteMembers(Set<Member> favoriteMembers)
{
this.favoriteMembers = favoriteMembers;
}
@ManyToMany(fetch=FetchType.LAZY)
@JoinTable(name=”product_specification”)
@OrderBy(“order asc”)
public Set<Specification> getSpecifications()
{
return this.specifications;
}
public void setSpecifications(Set<Specification> specifications)
{
this.specifications = specifications;
}
@ManyToMany(fetch=FetchType.LAZY)
@JoinTable(name=”product_specification_value”)
@OrderBy(“specification asc”)
public Set<SpecificationValue> getSpecificationValues()
{
return this.specificationValues;
}
public void setSpecificationValues(Set<SpecificationValue> specificationValues)
{
this.specificationValues = specificationValues;
}
@ManyToMany(mappedBy=”products”, fetch=FetchType.LAZY)
public Set<Promotion> getPromotions()
{
return this.promotions;
}
public void setPromotions(Set<Promotion> promotions)
{
this.promotions = promotions;
}
@OneToMany(mappedBy=”product”, fetch=FetchType.LAZY, cascade={javax.persistence.CascadeType.REMOVE})
public Set<CartItem> getCartItems()
{
return this.cartItems;
}
public void setCartItems(Set<CartItem> cartItems)
{
this.cartItems = cartItems;
}
@OneToMany(mappedBy=”product”, fetch=FetchType.LAZY)
public Set<OrderItem> getOrderItems()
{
return this.orderItems;
}
public void setOrderItems(Set<OrderItem> orderItems)
{
this.orderItems = orderItems;
}
@OneToMany(mappedBy=”gift”, fetch=FetchType.LAZY, cascade={javax.persistence.CascadeType.ALL})
public Set<GiftItem> getGiftItems()
{
return this.giftItems;
}
public void setGiftItems(Set<GiftItem> giftItems)
{
this.giftItems = giftItems;
}
@OneToMany(mappedBy=”product”, fetch=FetchType.LAZY, cascade={javax.persistence.CascadeType.REMOVE})
public Set<ProductNotify> getProductNotifies()
{
return this.productNotifies;
}
public void setProductNotifies(Set<ProductNotify> productNotifies)
{
this.productNotifies = productNotifies;
}
@ElementCollection(fetch=FetchType.LAZY)
@CollectionTable(name=”product_member_price”)
public Map<MemberRank, BigDecimal> getMemberPrice()
{
return this.memberPrice;
}
public void setMemberPrice(Map<MemberRank, BigDecimal> memberPrice)
{
this.memberPrice = memberPrice;
}
@ElementCollection(fetch=FetchType.LAZY)
@CollectionTable(name=”product_parameter_value”)
public Map<Parameter, String> getParameterValue()
{
return this.parameterValue;
}
public void setParameterValue(Map<Parameter, String> parameterValue)
{
this.parameterValue = parameterValue;
}
public void setProducts(Set<Product> products)
{
this.products = products;
}