使用场景:在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附近的中文括号替换成英文括号,问题解决。