spring boot jpahql语句报错 :antlr.NoViableAltException: unexpected token: roleName
Posted Angel挤一挤
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring boot jpahql语句报错 :antlr.NoViableAltException: unexpected token: roleName相关的知识,希望对你有一定的参考价值。
使用场景:在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>
问题所在:
roleName本身确实没有问题,但是它边上的(括号确实有问题
发现它跟前的括号缩紧和上面的括号缩进不一样,好吧 真恶心
解决问题:
把:roleName附近的中文括号替换成英文括号,问题解决。
以上是关于spring boot jpahql语句报错 :antlr.NoViableAltException: unexpected token: roleName的主要内容,如果未能解决你的问题,请参考以下文章
Spring Boot报错:Error creating bean with name 'sqlSessionFactory' ...
Spring Boot 项目导入 aliyun oss starter 依赖后启动报错的解决方案
Spring Boot 报错:Consider defining a bean of type ‘com.UserService‘ in your configuration.
Spring Boot 报错:Consider defining a bean of type ‘com.UserService‘ in your configuration.
Spring Boot 报错:Consider defining a bean of type ‘com.UserService‘ in your configuration.