我正在尝试执行 query ,但得到了由处理程序执行引起的 Resolved exception: org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.QueryException: Space is not allowed after parameter prefix ':' 。我按照这里的建议完成了 如何在休眠本机查询中使用 MySQL 分配运算符(:=)? 在这里: 遇到 mysql := 运算符时的休眠异常但相同。休眠版本 5.2.17.Final
ClientRepository.java
@Repository
public interface ClientRepository extends JpaRepository<Client, Long>, JpaSpecificationExecutor<Client> {
@Query( value = "select * from client where center_id in\n" +
"(select id from (select * from center order by parent_center_id, id) center_sorted, (select @pv=:centerId) initialisation\n" +
"where find_in_set(parent_center_id, @pv) and length(@pv:=concat(@pv, ',', id))) or center_id=:centerId;" ,nativeQuery = true)
Page<Client> findAllByCenterId(@Param("centerId") Long centerId, Pageable pageable) ;
}