HQL错误

空白-键 2011-10-19 03:07:54
语句如下:

from CustomerGroup group where 1=1 and ( group.oper = '0' or group.oper = 'super' ) order by group.createTime DESC


报错:

org.hibernate.hql.ast.QuerySyntaxException: expecting "by", found '.' near line 1, column 84 [ from com.XXXXXXXXX.hibernate.persistent.CustomerGroup group where 1=1 and ( group.oper = '0' or group.oper = 'super' ) order by group.createTime DESC]
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:258)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:157)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)


我试着把括号里面的group.去掉,语句改为

from CustomerGroup group where 1=1 and ( oper = '0' or oper = 'super' ) order by group.createTime DESC

就没问题了,这是什么原因,hibernate怎么处理括号的
...全文
73 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
空白-键 2011-10-19
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 qq497525725 的回复:]

group 是关键字
[/Quote]
晕死,还真是,我改为别的别名,就没问题了。
不过为什么我括号里面去掉别名就没问题
仙人长 2011-10-19
  • 打赏
  • 举报
回复
那里有个 near line 1, column 84 在原生sql再找是那个列
仙人长 2011-10-19
  • 打赏
  • 举报
回复
给你个建议 以下配置是产生原生sql 如果是sql问题可以将原生sql copy到sql工具上看
<property name="generate_statistics">true</property>
空白-键 2011-10-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 bohe_198878 的回复:]

from CustomerGroup as group
[/Quote]
有没有as没关系,加上也报错
qq497525725 2011-10-19
  • 打赏
  • 举报
回复
用了关键字 不知道什么时候就会报错,所以一定要避免关键字
qq497525725 2011-10-19
  • 打赏
  • 举报
回复
group 是关键字
bohe_198878 2011-10-19
  • 打赏
  • 举报
回复
from CustomerGroup as group

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧