日期:2014-05-20  浏览次数:21290 次

Hibernate中如何执行不等于查询?
使用getHibernateTemplate()查询数据库:
Java code
this.getHibernateTemplate().find("from mytable where id='0001'");

上面的代码可以正常执行,然后执行不等于查询
Java code
this.getHibernateTemplate().find("from mytable where id<>'0002'");

这次产生了错误,错误如下:
org.springframework.orm.hibernate3.HibernateQueryE xception: unexpected token: <> near line 1, column 41 [from mytable id <>'0002']; nested exception is org.hibernate.hql.ast.QuerySyntaxException: unexpected token: <> near line 1, column 41 [from mytable where id <>'0002']

然后将'<>'改为'!=' 还是产生错误:
org.springframework.orm.hibernate3.HibernateQueryE xception: unexpected token: != near line 1, column 41 [from mytable id !='0002']; nested exception is org.hibernate.hql.ast.QuerySyntaxException: unexpected token: != near line 1, column 41 [from mytable where id !='0002']

为什么会产生上面的错误,如何才能使用不等于查询?


------解决方案--------------------
from mytable id <>'0002' ??
where怎么没了