我有两个实体Issue
和Issue_Tracker
.
问题.java:
public class Issue implements Serializable
{
private Integer issue_id;
private String issue_description;
private Date issue_raised_date;
private Set<Issue_Tracker> issueTracker = new HashSet<Issue_Tracker>(0);
@OneToMany(fetch=FetchType.LAZY, mappedBy="issue_id")
public Set<Issue_Tracker> getIssueTracker() {
return issueTracker;
}
public void setIssueTracker(Set<Issue_Tracker> issueTracker) {
this.issueTracker = issueTracker;
问题跟踪器.java:
public class Issue_Tracker implements Serializable
{
private Integer issue_id;
private String tracker_status;
private Timestamp tracked_time;
当我离开时加入两个表,我使用查询得到以下数据:
SELECT issues.issue_id,
issues.issue_description,
issue_tracker.tracker_status,
issue_tracker.tracked_time
FROM issues
LEFT JOIN issue_tracker on issues.issue_id = issue_tracker.issue_id
WHERE issues.status = "Escalate To"
输出是
issue_id tracker_status tracked_time
123 Assigned 1/8/2013 11:44 //1st entry
123 Assigned 1/9/2013 11:45
123 Completed 1/10/2013 12:52 // last entry
32 Assigned 1/9/2013 16:46 //1st entry
32 Assigned 1/10/2013 18:46 //last entry
33 Assigned 1/9/2013 16:47 //1st entry
33 Cancel 1/9/2013 17:49 //last entry
现在,当我使用标准进行这些加入时,我得到了这些结果
issue_id tracker_status tracked_time
123 Assigned 1/8/2013 11:44 //1st entry of issue_id 123
32 Assigned 1/9/2013 16:46
33 Assigned 1/9/2013 16:47
使用以下标准
Criteria criteria = session.createCriteria(Issue.class);
criteria.setFirstResult(from);
criteria.setMaxResults(size);
criteria.setFetchMode("Issue.issueTracker",FetchMode.JOIN);
criteria.add(Restrictions.eq("status", "Escalate To"));
现在预期的输出是
issue_id tracker_status tracked_time
123 Completed 1/10/2013 12:52 // last entry
32 Assigned 1/10/2013 18:46 //last entry
33 Cancel 1/9/2013 17:49 //last entry
如何实现这一点,自从过去三天以来,我一直被困在这里,任何帮助都会很棒,是否因为我正在尝试一对多映射的这条线而发生
private Set<Issue_Tracker> issueTracker = new HashSet<Issue_Tracker>(0);
因为Set不允许重复值,如果是这样,可能的方法是什么。