目标是检索给定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.

最佳答案

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

尝试这个:

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

07-24 18:39