JPA,按集合排序查询上次日期值属性

时间:2017-11-28 09:17:40

标签: java jpa spring-data jpql

我的项目中有两个实体与hibernate关系

@Entity
class IssueEntity {

@OneToMany
List<CorrespondenceEntity> correspondenceList;
}

@Entity
public class CorrespondenceEntity {

Date modifyDate;

@ManyToOne
IssueEntity issue;
} 

可以使用JPQL创建查询,该查询通过Issue“对应列表”中包含的属性的最后(最大)日期从IssueRepository获取IssueEntity - “modifyDate”

1 个答案:

答案 0 :(得分:0)

是的,我知道问题是

  

使用JPQL

创建查询是否可行(或是否可行)

反正

  

JPA,按集合排序查询上次日期值属性

可以使用注释@OrderBy,例如

@OneToMany
@OrderBy("modifyDate DESC") // or "modifyDate ASC" whatever suits better
List<CorrespondenceEntity> correspondenceList;

请参阅API docs