我是Hibernate的新手,任何人都可以更正下面的SQL的HQL,找出目前正在为客户工作的独特员工。如果可能的话,请提供一些教程链接。
在解析SQL时,我能够从数据库中获取一些记录。也使用Native SQL,但是当我在HQL下面使用时,我无法接收任何记录。
SQL:
select distinct u.employeeid from employee u
inner join address ad on u.employeeid = ad.employeeid
left join company cp on (ad.oldcompanyid = cp.currentcompanyid and cp.wokingornot='Y')
left join client cl on (ad.oldcompanyid = cl.currentcompanyid and cl.wokingornot='Y')
where (u.lastdate is null and ad.lastdate is null)
and (cp.wokingornot = 'Y' or cl.wokingornot = 'Y');
请更正下面列出的HQL:
select distinct u from employee u ,address uo,company tp ,client mp
inner join u.address uo
left join uo.company tp with tp.wokingornot= true
left join uo.client mp with mp.wokingornot= true
where (u.lastdate is null and uo.lastdate is null)
and (tp.wokingornot= true or mp.wokingornot= true );
以下是我正在寻找HQL的实体:
public class employee {
public Int employeeid ;
public set<address> address;
public Date lastdate;
public Date Startdate;
}
public class address{
public int addressid;
public int oldcompanyid;
public employee employee;
public Date lastdate;
public Date Startdate;
}
public class company{
public int currentcompanyid;
public string wokingornot;
public address address;
}
public class client{
public int currentcompanyid;
public string wokingornot;
public address address;
}
答案 0 :(得分:0)
看起来会更像这样。您将从Employee类通过Address down到Company和Client类获得整个对象图。
select distinct u from employee u
join u.address uo
left join uo.company tp
left join uo.client mp
where u.lastdate is null and uo.lastdate is null
and (tp.wokingornot= true or mp.wokingornot= true )