我正在尝试执行一个查询,使用带有paegable的mySql fullText索引"match query“语法。
我将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);如果我也尝试将可分页设置为参数,同样的错误也会发生。
有什么想法吗?
发布于 2018-01-26 23:19:36
您不必在查询中显式地包含可分页。
请参阅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的当前发布版本,而不是里程碑版本。
发布于 2018-01-26 21:04:36
试着把可分页放在第一位:
Page<User> foo(Pageable pageable, @Param("filterValue") String filterValue);https://stackoverflow.com/questions/48461595
复制相似问题