我正在使用Spring Data JPA,当我@Query用来定义一个 WITHOUT 的查询时Pageable,它可以工作:
@Query
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。这是错误吗?
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); }
在Spring论坛上提出了一个类似的问题,指出要应用分页,必须派生第二个子查询。因为子查询引用的是相同的字段,所以您需要确保查询对引用的实体/表使用别名。这意味着您在哪里写了:
select * from internal_uddi where urn like
您应该改为:
select * from internal_uddi iu where iu.urn like ...