我正在尝试执行查询,但得到 已解决由处理程序执行引起的异常:org.springframework.dao.InvalidDataAccessApiUsageException:org.hibernate.QueryException:参数前缀":"后不允许有空格。我按照这里的建议做了如何在休眠本机查询中使用 MySQL 赋值运算符(:=)?在这里:遇到 mysql 时的休眠异常 := 运算符 但相同。休眠版本 5.2.17.Final
客户端存储库.java
@Repository
public interface ClientRepository extends JpaRepository<Client, Long>, JpaSpecificationExecutor<Client> {
@Query( value = "select * from client where center_id inn" +
"(select id from (select * from center order by parent_center_id, id) center_sorted, (select @pv=:centerId) initialisationn" +
"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) ;
}
以前,在本机查询中使用赋值运算符时,Hibernate抛出了异常。Hibernate支持转义冒号字符,而不是将其视为参数。因此,您需要使用反斜杠进行转义。 : "\\:="
请注意,引用占位符前后不允许有空格。