0
我有問題編寫HQL以顯示不同的applicationId與最新的應用程序(newest createDate)爲表中的以下數據。HQL查詢幫助
+---------------+-------------+----------+---------------------+
| applicationId | firstName | lastName | createDate |
+---------------+-------------+----------+---------------------+
| 1 | Mark | Johnson | 2010-05-03 00:00:00 |
| 3 | Henry | Jordan | 2010-05-03 00:00:00 |
| 5 | Cindy Spahn | Wilson | 2010-05-03 00:00:00 |
| 5 | Cindy Spahn | Wilson | 2010-05-04 00:00:00 |
| 5 | Cindy Spahn | Wilson | 2010-05-05 00:00:00 |
+---------------+-------------+----------+---------------------+
5 rows in set (0.00 sec)
下面是我在尋找的結果:
+---------------+-------------+----------+---------------------+
| applicationId | firstName | lastName | createDate |
+---------------+-------------+----------+---------------------+
| 1 | Mark | Johnson | 2010-05-03 00:00:00 |
| 3 | Henry | Jordan | 2010-05-03 00:00:00 |
| 5 | Cindy Spahn | Wilson | 2010-05-05 00:00:00 |
+---------------+-------------+----------+---------------------+
3 rows in set (0.00 sec)
實體如下:
@Entity
@Table(name = "application")
public class Application {
private long applicationId;
private String firstName;
private String lastName;
private List<ApplicationHistory> applicationHistoryList;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public long getApplicationId() {
return applicationId;
}
@OneToMany(mappedBy = "application", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
public List<ApplicationHistory> getApplicationHistoryList() {
return applicationHistoryList;
}
// getter() and setter()
}
和:
@Entity
@Table(name = "applicationHistory")
public class ApplicationHistory {
private Application application;
private final Timestamp createDate = new Timestamp(System.currentTimeMillis());
@ManyToOne
@JoinColumn(name = "applicationId", insertable = false, updatable = false)
public Application getApplication() {
return application;
}
@Id
@Column(columnDefinition = "timestamp default current_timestamp")
public Timestamp getCreateDate() {
return createDate;
}
}
我不明白第一個 「表」 應該說明。請發佈來自兩個表格(Application和ApplicationHistory)的實際數據樣本。 – 2010-08-26 07:18:27