我正在使用Spring Data JPA,当我使用@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
。这是一个错误吗?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);
}
最佳答案
类似的问题是asked on the Spring forums,指出要应用分页,必须派生第二个子查询。因为子查询引用了相同的字段,所以您需要确保查询为其引用的实体/表使用别名。这意味着您在哪里写了:
select * from internal_uddi where urn like
您应该改为:
select * from internal_uddi iu where iu.urn like ...