说我有以下实体
class Order {
@Id
private long id;
private long orderNo;
@OneToMany
@JoinColumn(name="order_id")
@OrderBy("timeStamp ASC")
private List<Item> items;
}
class Item {
@Id
private long id;
// e.g. COMPLETED, IN PROGRESS, QUEUED, etc...
private String status;
private long timeStamp;
@ManyToOne
private Order order;
}
使用JPA我想返回一个订单列表,这些订单按照项目列表中最后一个项目的状态排序,这是最新的一个,因为项目是按时间顺序排序的。怎么办呢?
答案 0 :(得分:2)
类似的东西,
Select o from Order o join o.items i where i.id = (Select max(timestamp) from Item i2 where i = i2) order by i.status