小编Jay*_*ary的帖子

NonUniqueResultException:JPARepository Spring 启动

我正在使用SpringBootJPAQueryDSL我已经编写了一个HQL从表中获取一些自定义记录的方法,但它抛出了Exception。下面我提到存储库的代码:

@Repository
public interface LoanOfferRepository extends JpaRepository<LoanOffer, Long>, QuerydslPredicateExecutor<LoanOffer> {

    @Query("select lo.startDate,count(*) from LoanOffer lo where lo.loan.fsp= :fsp and lo.startDate between :fromDate and :toDate Group by lo.startDate")
    public Map<LocalDate,Integer> getLastMonthLoans(@Param("fsp")Fsp fsp,@Param("fromDate")LocalDate fromDate,@Param("toDate")LocalDate toDate);
}
Run Code Online (Sandbox Code Playgroud)

每当我调用此方法时,getLastMonthLoans()我都会收到以下异常:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.IncorrectResultSizeDataAccessException: query did not return a unique result: 9; nested exception is javax.persistence.NonUniqueResultException: query did not …
Run Code Online (Sandbox Code Playgroud)

hibernate hql spring-data-jpa spring-boot

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

hibernate ×1

hql ×1

spring-boot ×1

spring-data-jpa ×1