大创项目需要添加前端传输过来的某两个属性之间的关系, 1;2 这种。使用hql查询数据库中是否存在该关系时报错。
where grade ="+grade+" and majorId ="+majorId+" and relation ="+relation);
java.lang.IllegalArgumentException: org.hibernate.QueryException: unexpected char: ‘;’ [from com.jou.oe.entity.FunTrainProgramReqtogoal where grade =2020 and majorId =10056 and relation =1;2
发现是hql语句只识别了最后的 and relation =1 而之后的;2识别不了 所以会报此异常。
解决方法:
将relation用 ‘ 包裹起来即可。
where grade ="+grade+" and majorId ="+majorId+" and relation ="+"\'"+relation+"\'");