日期:2014-05-16  浏览次数:20635 次

mysql+hibernate写HQL语句时报错 unknown column ‘XXX’ in where clause

单从字面上是列名不存在,但是实际上却是因为少写了单引号而引起的, 例如:(其中id是用uuid生成,对应是string类型) List list2 =session.createQuery("from User where id= "+"ff8080812d9f1104012d9f11053a0001").list(); 则会报一下错误 Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'ff8080812d9f1104012d9f11053a0001' in 'where clause' 修改HQL如下 List list2 =session.createQuery("from User where id= '"+"ff8080812d9f1104012d9f11053a0001"+"'").list(); 成功运行