【发布时间】:2009-08-26 23:26:19
【问题描述】:
我正在使用 java 持久性来保存与另一个实体关联的实体列表。以下是我遇到问题的简要说明。
@Entity public class Offer implements Serializable {
@Id private Long offerId;
@OneToMany
@Column List<OfferCategory> offerCategories;
}
@Entity public class OfferCategory implements Serializable {
@Embeddable public static class Id implements Serializable
{
@Column(name="offer_id")
private Long offerId;
@Column(name="category_id")
private Long categoryId;
public Id() {}
public Id(Long offerId, Long categoryId) {
this.offerId = offerId;
this.categoryId = categoryId;
}
public boolean equals(Object o) {
if(o != null && o instanceof Id) {
Id other = (Id) o;
return this.offerId.equals(other.offerId) &&
this.categoryId.equals(other.categoryId);
}
else
return false;
}
public int hashCode() {
return offerId.hashCode() + categoryId.hashCode();
}
}
@EmbeddedId private Id id = new Id();
}
基本上,由于我无法更改的架构,我需要将类别列表保存为分配给优惠。
现在,我从用户那里获取了一个类别列表,然后将它们放入 Offer 的 offerCategories 字段中。但是,这不适用于新商品,因为我无法设置新商品的 ID。
我是 JPA 和 Seam 的新手,所以如果有人能在正确的方向上给我一点建议,我将不胜感激。
【问题讨论】:
标签: java jpa persistence seam