所以,在这种情况下:
表ComputerInventory
与{computerInventoryID (Primary key), TagID(unique), Name etc}
表reviewStatus
与{reviewStatusID(Primary key), computerInventoryID (ForeignKey), status }
我为ReviewStatus
编写了hibernate实体:
public class ReviewStatus implements Serializable {
public enum reviewStatus {
To_Be_Reviewed,
Reviewed
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long reviewStatusId;
@Column(name = "lastModifiedTime")
private Date lastModifiedTime;
@Column(name = "Comments")
private String comments;
@Enumerated(EnumType.STRING)
@Column(name = "status")
//all above params have gettetrs and setters
private reviewStatus status;
//TODO: Mapping to computerinventory
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "computerInventoryId")
//For one ComputerInventoryID, there can be many review Statuses.
private Set<ReviewStatus> reviewStatusSet;
public long getreviewStatusId() {
return reviewStatusId;
}
我的怀疑: 对于一个ComputerInventoryID,可以有许多评论状态,所以我有一个
Set<ReviewStatus> reviewStatusSet
我在reviewstatus中返回条目列表?对不起,但我不明白如何写一个get / set来返回并设置一堆记录的评论状态。
答案 0 :(得分:1)
您对ReviewStatus的引用应该是ComputerInventory,而不是它的ID。 Hibernate允许您抽象出主键(ID)的细节,让您直接从一个对象引用到另一个对象。您应该在@ManyToOne
上使用private ComputerInventory computerInventory;
注释。