当前位置: 代码迷 >> J2EE >> hibernate 查询报错QuerySyntaxException解决方法
  详细解决方案

hibernate 查询报错QuerySyntaxException解决方法

热度:76   发布时间:2016-04-22 01:19:46.0
hibernate 查询报错QuerySyntaxException
HQL
hql = " select teb from A teb,B tt where teb.state='1' and (teb.startdate>=? || teb.enddate<=?) and teb.templateID=tt.templateId

错误信息 
 org.springframework.orm.hibernate3.HibernateQueryException: unexpected token: ||
Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: || near line 1, column 146 [ select teb from A teb,B tt where teb.state='1' and (teb.startdate>=? || teb.enddate<=?) and teb.templateID=tt.templateId ]
Caused by: line 1:146: unexpected token: ||

请问到底怎么回事。。。||不能用?可是在另外一个地方也是写的一样的语句就可以 实在郁闷~这句HQL语句我改成SQL放在PL/SQL里面运行也是不行的.不知道到底哪里有问题~



------解决方案--------------------
|| 换成 or
------解决方案--------------------
hibernate最终还是会换成sql语句去执行的、只不过他帮你写了对应的sql语句、

楼主学java学入迷了啊、
------解决方案--------------------
楼上正解,||是java的语法,or才是数据库语法
------解决方案--------------------
呵呵.楼主要注意了哈.
  相关解决方案