我有两个实体问题和Issue_Tracker
。我在一对多映射中加入了这两个表。在Issue_Tracker
中,我们可以有多个条目,例如
issue_id tracker_status tracked_time
123 Assigned 1/8/2013 11:44
123 Assigned 1/8/2013 11:45
123 Completed 1/8/2013 11:52
32 Assigned 1/9/2013 16:46
33 Assigned 1/9/2013 16:47
33 Cancel 1/9/2013 16:49
我想通过 tracked_time 订购 Issue_tracker 实体,因此我只能获得最后一次更新tracker_status
。我正在使用标准来获取数据,但是我得到了第一个条目,例如:对于 issue_id 123,我将 tracker_status 设置为 Assigned ,但我想tracker_status : Completed
获取id 123. 如何做到这一点。我的DAO如下
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"));
return criteria.list();
问题.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;
Issue_Tracker.java
public class Issue_Tracker implements Serializable
{
private Integer issue_id;
private String tracker_status;
private Timestamp tracked_time;
我希望你们能得到我想问的问题,有什么帮助吗?