【问题标题】:HQL left join where left is nullHQL left join where left 为空
【发布时间】:2011-03-22 15:40:06
【问题描述】:
如何在 HQL 上编写此查询:
select pp.*
from Part pp
left join Product p on pp.ProductID = p.ID
where p.ID is null
我需要没有产品的零件。部件具有属性产品(多对一)
我试过了
from Part p
where p.Product is null
但它会生成无效的查询。
谢谢
【问题讨论】:
标签:
nhibernate
nhibernate-mapping
hql
【解决方案1】:
解决方法:
from Part p
where not exists (from Product pr where p.Product = pr)
更新:
这与 SQL 完全一样!
from Part p
left join p.Product as pr
where pr is null
【解决方案2】:
from Part p
where p.Product.Id is null
应该可以
尽管您的查询也应该有效。您得到的生成查询是什么?