Spring Data JPA-首先按枚举查找,然后按日期顺序

时间:2018-10-08 02:26:44

标签: java spring-data-jpa jpql

目标是检索给定UAI(枚举)的最后一个实体。不确定在Spring Data JPA中执行此操作的最佳方法是什么,这是我尝试过的方法(不起作用)

我的实体

public class AdmisHistory {
    // stuffs (id etc..)

    private Date jobExecutionDate;

    @Enumerated(EnumType.STRING)
    private UAI uai;

   // getters / setters
}

我的JPA存储库:

public interface AdmisHistoryRepository extends CrudRepository<AdmisHistory, Long> {
   public AdmisHistory findFirstByOrderByUaiByJobExecutionDateDesc(UAI uai);
}

错误:

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property byJobExecutionDate found for type UAI! Traversed path: AdmisHistory.uai.

1 个答案:

答案 0 :(得分:2)

您想通过uai进行比赛并获得最新记录

尝试一下:

public interface AdmisHistoryRepository extends CrudRepository<AdmisHistory, Long> {
   public AdmisHistory findTopByUaiOrderByJobExecutionDateDesc(UAI uai);
}