ITeye博客

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

东流水 · 2011-01-24 23:04 · 企业架构 · Markdown

单从字面上是列名不存在,但是实际上却是因为少写了单引号而引起的, 例如:(其中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(); 成功运行

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。