日期:2014-05-17  浏览次数:20592 次

hibernate hql多表查询
表1:Employee (id, name, department)
表2:Advice (id, employeeId, departmentId)
两表之间不设置外键

select E.id,E.name from Employee E left join(
select employee_Id from Advice where department_Id =39006
)A on A.employee_Id = E.id where A.employee_Id is null and E.department_id =39006

上面的sql语句在oracle中可以成功执行

但是作为hibernate hql执行就报错

把left join .....on ...  改为left join .... with ....也是报错

求教hibernate hql应该怎么写

------解决方案--------------------
hibernate使用hql的join语句的时候是不允许用on的.用了on只会hql语句报错。
你只要在Advice 和Employee 两个实体类上设置好关联关系
select e.id,e.name from Employee e left join Advice a where a.departmentId=39006
这样写就行了
------解决方案--------------------
不推荐使用 连接查询
实在想用 还是使用 SQL语句吧
然后把返回的数据 transform一下,这样数据就对象化了.