0

假设我有以下实体

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,我想返回按项目列表中最后一个项目的状态排序的订单列表,这是最新的,因为项目是按时间戳排序的。如何才能做到这一点?

4

1 回答 1

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
于 2013-03-25T14:27:48.393 回答