当前位置: 代码迷 >> J2EE >> Hibernate中怎么执行不等于查询
  详细解决方案

Hibernate中怎么执行不等于查询

热度:413   发布时间:2016-04-22 03:24:22.0
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怎么没了
  相关解决方案