IssueとIssue_Trackerの 2 つのエンティティがあります。私は休止状態 3.6 と 1 対多の関連付けを使用しています。
問題.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;**
そして、これはSQLクエリです。基準を使用してこれを達成する方法
SELECT i.issue_id, i.issue_description,
it.tracker_status, it.tracked_time
FROM issues i
LEFT JOIN ( SELECT it.issue_id, it.tracker_status, it.tracked_time
FROM issue_tracker it
INNER JOIN (SELECT issue_id, MAX(tracked_time) tracked_time
FROM issue_tracker GROUP BY issue_id
) A ON it.issue_id = A.issue_id AND it.tracked_time = A.tracked_time
) it ON i.issue_id = it.issue_id
WHERE i.status = "Escalate To";