org.hibernate.QueryException: Space is not allowed after parameter prefix ':'

北慕城南 提交于 2020-01-16 14:11:15

问题


I'm trying to execute query , but got Resolved exception caused by handler execution: org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.QueryException: Space is not allowed after parameter prefix ':' . I done as advised here How can I use MySQL assign operator(:=) in hibernate native query? and here : Hibernate exception on encountering mysql := operator But same. hibernate version 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) ;

}


回答1:


Formerly, when using the assignment operator in Native Query, Hibernate threw an exception.Hibernate supports escaping the colon char not to treat it as a parameter. So, You need to escape with a backslash. : "\\:="

Note that no spaces are allowed before and after the reference placeholder.



来源:https://stackoverflow.com/questions/54116487/org-hibernate-queryexception-space-is-not-allowed-after-parameter-prefix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!