使用场景:在spring data jpa下使用@Query("hql语句")

然后在项目启动的时候报错

hql语句报错:antlr.NoViableAltException: unexpected token: roleName

仔细查看了一下代码:

 @Query(value =
    "from Role as r left join r.department as d left join d.company as c where" +
            " (:departmentId is null or d.id = :departmentId)" +
            " and (:companyId is null or c.id = :companyId)"+
            " and (:roleName is null or r.name = :roleName)"
    )
    fun searchRole(
            @Param("departmentId") departmentId: Long? = null,
            @Param("companyId") companyId: Long? = null,
            @Param("roleName") roleName: String? = null
    ): Set<Role>

【spring boot jpa】hql语句报错 :antlr.NoViableAltException: unexpected token: roleName

 

问题所在:

roleName本身确实没有问题,但是它边上的(括号确实有问题

发现它跟前的括号缩紧和上面的括号缩进不一样,好吧  真恶心

 

解决问题:

把:roleName附近的中文括号替换成英文括号,问题解决。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
  • 2021-09-30
  • 2022-02-16
猜你喜欢
  • 2021-09-01
  • 2021-11-28
  • 2022-01-21
  • 2021-06-23
  • 2022-01-28
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案