我有以下域模型:
class Department {
Contact primaryContact
Company company
}
当我执行 JPQL 查询时
from Department e
left join e.primaryContact
where (e.company.id=?) order by e.name asc
我得到以下 SQL:
select *aliases*
left outer join contact contact1_
on department0_.contact_id=contact1_.ID
where
department0_.company_id=?
order by department0_.name desc
但是当我试图执行
from Department e
left join e.primaryContact
where (e.insuranceCompany.id=?)
order by e.primaryContact.name asc
我得到:
select *aliases*
from department department0_
left outer join contact contact1_ on
department0_.primary_contact_id = contact1_.ID
cross join contact contact2_
where
department0_.primary_contact_id = contact2_.ID
and department0_.company_id = ? order by contact2_.name desc
不同的是
cross join contact contact2_ where department0_.primary_contact_id=contact2_.ID
所以我在排序时总是有内部连接primaryContact.name
在这种情况下如何执行左连接?(我使用的是休眠 3.6.10)
先感谢您。