報錯信息:
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)]
括號不匹配:SQL 末尾缺少右括號 `)`。完整 WHERE 子句以 `(` 開頭,但 `not exists` 子查詢結束後缺少閉合主查詢的右括號。
select count(*) from 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 UserRole b
where b.role.id = :roleId and b.user.id = t.id
)
養成格式化寫法 + 分層驗證習慣,可消除 90% 的 HQL 語法異常。