日期:2014-05-18  浏览次数:20596 次

HQL语句报错
本帖最后由 wuwenzhe 于 2013-04-17 18:36:48 编辑
这句话是我写的HQL查询语句:


String queryString = "select a.id,a.authority.id,a.name,a.description,b.id,b.name from Authority a left outer join Authority b where a.authority.id = b.id and a.authority.id is not null";



下面是报的错误:



803 ERROR [org.hibernate.hql.PARSER] (http--127.0.0.1-8080-1)  Path expected for join!
18:31:30,806 ERROR [org.hibernate.hql.PARSER] (http--127.0.0.1-8080-1)  Invalid path: 'b.id'
18:31:30,808 ERROR [org.hibernate.hql.PARSER] (http--127.0.0.1-8080-1)  Invalid path: 'b.id'
18:31:30,809 ERROR [org.hibernate.hql.PARSER] (http--127.0.0.1-8080-1)  right-hand operand of a binary operator was null
18:31:30,809 ERROR [org.hibernate.hql.PARSER] (http--127.0.0.1-8080-1) <AST>:0:0: unexpected end of subtree
18:31:30,810 ERROR [dao.AuthorityDAO] (http--127.0.0.1-8080-1) find all failed: org.hibernate.hql.ast.QuerySyntaxException: Path expected for join! [select a.id,a.authority.id,a.name,a.description,b.id,b.name from pojo.Authority a left outer join Authority b where a.authority.id = b.id and a.authority.id is not null]



相同意思的sql语句直接操作数据库

  select a.id,a.parentRightID,a.name,b.id,b.name from [wgzxdms].[dbo].[authority] a left join [wgzxdms].[dbo].[authority] b 
  on a.parentRightID = b.id



就能得到正确的结果

------解决方案--------------------
private Authority authority;在这个类中,定义这个对象,有意义吗?
改为:
select a.id,a.name,a.description,b.id,b.name from Authority a left join Authority b on a.id = b.id where a.id is not null
------解决方案--------------------
既然你都用了hibernate,父对象a.authority可以通过hibernate内部的机制获取,为啥还要自己写HQL?
------解决方案--------------------
select a.id,a.name,a.description,b.id,b.name from pojo.Authority as a left join a.authority as b
先试试前面,
再看添加条件 where b.id is not null