org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: null near line 1, column 290 [select count(*) from cn.com.taiji.sample.entity.User t where 1=1 and (t.name like :userName or t.namePy like :userName or t.loginName like :userName and t.status =:status and not exists(select b.user from cn.com.sample.entity.UserRole b where b.role.id =:roleId and b.user.id = t.id)]
這是我報的錯誤,報錯的原因屬於語法格式的錯誤,整個HQL語句也在這里,結合網上查找的解決辦法,總結如下:
1、多余的空格;
2、字符串引號應該為單引號;
3、=:應該是在一起的,中間沒有空格,‘like :’中介需要有空格,其實這里沒這么嚴謹,只是以防萬一;
4、括號,我出的問題就是左括號比右括號多了一個;
5、一條SQL或者HQL語句中只能有一個order by(在沒有子查詢的前提下),所以如果有多個需要參照的排序條件,那么就在order by后加上,每個條件之間用逗號隔開,比如:
from Topic t order by t.postTime desc,t.lastUpdatedTime asc;
可能還有其他原因,希望對大家有幫助!