Path expected for join!错误

一:

ExpertTreatment是多对一关系

hql语句:

String hql = "select new Map(t.treatment_Id as treatment_Id ,t.name as name,count(e.Treatment) as countTreatment) from Treatment t  left join Expert e on t.treatment_Id = e.treatment";

报错信息:

org.hibernate.hql.internal.ast.QuerySyntaxException: Path expected for join!

原因:hql不支持join语法。

二:

原因看了这博主:http://blog.csdn.net/mikyz/article/details/69397998

https://stackoverflow.com/questions/28234754/jpa-exception-path-expected-for-join


改hql成:(join Expert.Treatment)

String hql = "select new Map(t.treatment_Id as treatment_Id ,t.name as name,count(e.Treatment) as countTreatment) from Expert e right join Expert.Treatment t on t.treatment_Id = e.treatment";

还是报错:
ERROR:  Invalid path: 'null.Treatment'

再修改,成功:count(e.treatment),e.treatment

String hql = "select new Map(t.treatment_Id as treatment_Id ,t.name as name,count(e.treatment) as countTreatment) from Expert e right join e.treatment t on t.treatment_Id = e.treatment";


你可能感兴趣的:(Path expected for join!错误)