org.hibernate.QueryException: Space 不允许出现在参数前缀 ':' 之后
org.hibernate.QueryException: Space is not allowed after parameter prefix ':'
我正在尝试执行查询,但是得到了
已解决由处理程序执行引起的异常:org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.QueryException: Space is not allowed after parameter prefix ':' .
我按照这里的建议做了
How can I use MySQL assign operator(:=) in hibernate native query?
和这里 :
但是一样。
休眠版本 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) ;
}
以前,当在 Native Query 中使用赋值运算符时,Hibernate 抛出一个 exception.Hibernate 支持转义冒号字符而不将其视为参数。
所以,你需要用反斜杠转义. : "\\:="
请注意,引用占位符前后不允许有空格。
我正在尝试执行查询,但是得到了
已解决由处理程序执行引起的异常:org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.QueryException: Space is not allowed after parameter prefix ':' .
我按照这里的建议做了
How can I use MySQL assign operator(:=) in hibernate native query?
和这里 :
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) ;
}
以前,当在 Native Query 中使用赋值运算符时,Hibernate 抛出一个 exception.Hibernate 支持转义冒号字符而不将其视为参数。 所以,你需要用反斜杠转义. : "\\:="
请注意,引用占位符前后不允许有空格。