我有以下SQL查询,我试图转换为HQL。不幸的是,外部联接从来不是我最喜欢处理的。
SELECT DISTINCT T_EMPLOYEE.SSN,
T_EMPLOYEE.TRANSACTION_ID,
T_EMPLOYEE.NAME,
T_EMPLOYEE.CANCEL_DATE,
T_EMPLOYEE.CAN_USERID,
T_DEPARTMENT.LOC FROM T_EMPLOYEE,
T_DEPARTMENT
WHERE ( T_EMPLOYEE.DEPARTMENT_CODE = T_DEPARTMENT.CODE (+)) and
( ( T_EMPLOYEE.SSN = :s_ssn ) )
我知道where的右边的(+)符号是Oracle的旧式外连接序列(因为它在右边是一个左外连接)。 T_EMPLOYEE和T_DEPARTMENT(旧数据库)之间也没有外键关系。
两个问题: 1.在没有外键关系的情况下,HQL中是否可以使用theta样式(即using =)外连接? 2.如果是这样,有人可以帮助我将其转换为HQL吗?
杰森
答案 0 :(得分:0)
假设
class Employee
{
private Department department;
}
<many-to-one name="department" column="DEPARTMENT_CODE" />
class Department
{
private long id;
}
<id name="id" column="CODE" ><generator class="assigned" /></id>
然后通过
获得急切加载的部门的员工"FROM Employee e join fetch e.Department d WHERE e.SSN = :s_ssn"
或仅包含您想要的列
"SELECT DISTINCT e.ssn, ..., d.loc FROM Employee e left outer join e.Department d WHERE e.SSN = :s_ssn"