Spring Data JPA:本机摘要获取ConverterNotFoundException

问题描述 投票:1回答:1

我在Repository类中有2个本机查询。一种键入返回所有记录,另一种仅返回一行。见下文:

@Query(nativeQuery = true, value = NATIVE_SUMMARY_QUERY_PARTIAL + "group by (rjd.refresh_job_identifier)) as rc")
List<RefreshSummary> getRefreshJobDetailSummary();

@Query(nativeQuery = true, value = NATIVE_SUMMARY_QUERY_PARTIAL + " WHERE rjd.refresh_job_identifier = :refreshJobId" +
        " group by (rjd.refresh_job_identifier)) as rc")
RefreshSummary getRefreshJobDetailSummaryById(@Param("refreshJobId") String refreshJobId);

interface RefreshSummary {
    String getRefreshJobId();
    Date getRefreshJobStart();
    Date getRefreshJobComplete();
    String getUserId();
    long getTotalRecords();
    long getSuccessfulRecords();
    long getPendingRecords();
    long getErrorRecords();
    long getCancelledRecords();
    String getRefreshJobStatus();
}

String NATIVE_SUMMARY_QUERY_PARTIAL = "SELECT  rc.refresh_job_identifier as refresh_job_id, ..."

第一种方法getRefreshJobDetailSummary可以正常工作。但是第二种方法,我只需要一行,却给了我这个例外:

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [com.trp.erd.repository.RefreshJobDetailRepository$RefreshSummary]

查询返回的值如下:

'{20191218204913458trphc35, 2019-12-18 20:49:13.314, 2019-12-18 20:49:24.335, trphc35, 1, 1, 0, 0, 0, Complete}'

有人可以对此进行说明吗?为什么一种方法有效,而另一种无效?

hibernate jpa spring-data-jpa
1个回答
0
投票

我将把第二种方法的返回类型从RefreshSummary替换为List<RefreshSummary>。从理论上讲,您的方法应该返回一个列表,而不是单个值

热门问题
推荐问题
最新问题