HQL right outer join

*爱你&永不变心* 提交于 2019-12-06 06:11:41
Sarah

The problem is with the way you've written your query. Because you use O.customer.XXXX, Hibernate adds an inner join between Order and Customer to the query in order to resolve O.customer. You need to re-write your query to use the results of the right inner join by introducing an alias for O.customer in the right inner join.

select C.id as id, C.firstName as firstName, C.lastName as lastName, 
  C.address as address, C.city as city, count(O.id) as totalOrders 
from Order O right outer join O.customer C 
group by C.id

If you were to look at the SQL that hibernate generated from your query, you would see that it is performing both an inner join and a right inner join between Order and Customer.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!