我的實體的樣子:秩序JPA標準API
class News {
private Long id;
private Author author;
private List<Tag> tagsList;
private String title;
private List<Comment> commentsList;
private Date modificationDate;
}
1)我想通過房產大小和日期排序結果列表。
我的代碼的一部分:
cq.select(from).distinct(true)
.orderBy(cb.desc(from.get("commentsList.size")), cb.desc(from.get("modificationDate")));
當然的 「.size」 是錯誤的。我如何使用標準API做到這一點?
2)如何在條件中添加Tags
從tagsList
和Author
?
集合的大小是通過CriteriaBuilder.size完成的(......)與參數是「from.get(」commentsList「)」。試過了嗎? –
[構建JPA Criteria API查詢 - 按集合中元素的數量進行排序]的可能重複(http://stackoverflow.com/questions/21005794/building-jpa-criteria-api-query-sorting-by-number-of- elements-in-collection) – riskop