`

hql unexpected token 错误解决【原创】

阅读更多

String hql = "from TIssue where id in ('167','169','170','171','172','173') and object = ',B01,'";
这句在程序里面跑~
抛错:
ERROR org.hibernate.hql.PARSER - line 1:26: unexpected token: object
之前是:
String hql = "from TIssue where id in ('167','169','170','171','172','173')";
没错~

我检查了TIssue这个类,确实有:
private String object;
这个bean的setter和getter
也检查了
TIssue.hbm.xml
发现里面是:
         <property name="object" type="java.lang.String">
             <column name="OBJECT" length="1000">
                 <comment>布发对象,头尾和对象间均加半角逗号</comment>
             </column>
         </property>

最后的解决办法是用别名来:

String hql = "from TIssue sue where sue.id in ('167','169','170','171','172','173') and sue.object = ',B01,'";

 

就行了~可能是hibernate把字段object当成了关键字,或是hql要别名才不会报奇怪的错?总之是这样解决了~

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics