我尝试使用mySql fullText索引进行查询"匹配"带有paegable的语法。
我将spring-boot版本从1.5.4.RELEASE更改为2.0.0m7以使用spring-data-jpa版本2.0.2.RELEASE,因为在早期的spring-data-jpa版本中,使用了一个本机查询countQuery没有工作。
目前的问题是以下错误:
javax.servlet.ServletException: org.springframework.orm.jpa.JpaSystemException: could not execute query; nested exception is org.hibernate.exception.GenericJDBCException: could not execute query
...
Caused by: java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).
这是代码
@Query( value = "SELECT Distinct u.* " +
"FROM user AS u " +
"WHERE MATCH(u.name, u.email) against(:filterValue) " +
"ORDER BY u.id \n#pageable\n#",
countQuery = "SELECT count(Distinct u.id) " +
"FROM user AS u " +
"WHERE MATCH(u.name, u.email) against(:filterValue) " +
"ORDER BY u.id \n#pageable\n#",
nativeQuery = true)
Page<User> foo(@Param("filterValue") String filterValue, Pageable pageable);
如果我尝试将可分页设置为参数,则会发生同样的错误。
有什么想法吗?
答案 0 :(得分:0)
您不必在查询中明确包含可分页。
请参阅the reference documentation中的示例。
public interface UserRepository extends JpaRepository<User, Long> {
@Query(value = "SELECT * FROM USERS WHERE LASTNAME = ?1",
countQuery = "SELECT count(*) FROM USERS WHERE LASTNAME = ?1",
nativeQuery = true)
Page<User> findByLastname(String lastname, Pageable pageable);
}
我强烈建议您升级到Spring Data的当前发行版,而不是里程碑版本。
答案 1 :(得分:-1)
尝试将Pageable放在第一位:
Page<User> foo(Pageable pageable, @Param("filterValue") String filterValue);