从Spring Data Jpa查询返回的对象具有空值

我正试图从JPA Repository获取自定义类型的对象

visit repository.Java

@Repository
public interface VisitRepository extends JpaRepository<Visit, Long>, JpaSpecificationExecutor<Visit> {
    @Query(value = "select client_id , count(*) from visit  where (DATE(jhi_date) between :startDate and :endDate) group by client_id",nativeQuery = true)
    List<IIntegerReportData> findByDate(@Param("startDate") String startDate, @Param("endDate") String endDate);

I integer report data.Java

package com.mycompany.hiptest.repository;

public interface IIntegerReportData {
    Long getId();
    Integer getValue();
}

client rating.Java

 public List<ClientsRatingDTO> findAllSorted(String startDate, String endDate, Long fieldNum) {
        List<IIntegerReportData> visitReport = visitRepository.findByDate(startDate, endDate);   
        log.debug("visitReport:" + visitReport.size());

        for (IIntegerReportData visit : visitReport
        ) {
            log.debug("value: " + visit.getValue());
          }

在调试中我得到visitReport.size()= 27(这是正确的记录计数),但是 每个行的visit.getValue()为NULL,但每个行的此字段中没有空值。怎么了?

0
投票

您可以使用NativeQuery Annotation:

看一下:

https://www.baeldung.com/spring-data-jpa-query