因此,情况如下:

ComputerInventory{computerInventoryID (Primary key), TagID(unique), Name etc}

reviewStatus{reviewStatusID(Primary key), computerInventoryID (ForeignKey), status }

我为ReviewStatus编写了休眠实体:

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中的条目列表?抱歉,但是我不明白如何编写获取/设置来返回和设置一堆记录的评论状态。

最佳答案

您从ReviewStatus引用的应该是ComputerInventory,而不是其ID。 Hibernate使您可以抽象出主键(ID)的详细信息,从而可以直接从一个对象引用到另一个对象。您应该在@ManyToOne上使用private ComputerInventory computerInventory;批注。

10-06 10:54