小编典典

Spring数据JPA @查询和可分页

hibernate

我正在使用Spring Data JPA,当我@Query用来定义一个 WITHOUT 的查询时Pageable,它可以工作:

public interface UrnMappingRepository extends JpaRepository<UrnMapping, Long> {
    @Query(value = "select * from internal_uddi where urn like %?1% or contact like %?1%", 
           nativeQuery = true)
    List<UrnMapping> fullTextSearch(String text);
}

但是,如果我添加第二个参数Pageable@Query则将无法正常工作,Spring将解析该方法的名称,然后抛出 异常 No property full found。这是错误吗?

public interface UrnMappingRepository extends JpaRepository<UrnMapping, Long> {
    @Query(value = "select * from internal_uddi where urn like %?1% or contact like %?1%",
           nativeQuery = true)
    Page<UrnMapping> fullTextSearch(String text, Pageable pageable);
}

阅读 256

收藏
2020-06-20

共1个答案

小编典典

在Spring论坛上提出了一个类似的问题,指出要应用分页,必须派生第二个子查询。因为子查询引用的是相同的字段,所以您需要确保查询对引用的实体/表使用别名。这意味着您在哪里写了:

select * from internal_uddi where urn like

您应该改为:

select * from internal_uddi iu where iu.urn like ...
2020-06-20