使用Spring 4.1.4,Spring Data 1.7.1,Hibernate 4.3.8
出于性能原因,我试图让左连接提取工作在JPQL中,但是在SubItem1有0个条目的情况下,我不会回到我的实体。
我的JPQL看起来像这样:
@Query("select distinct foo from Foo foo
join fetch foo.parentItem pi
left join fetch pi.ZeroOrMoreChildren zChild
join fetch zChild.parentOfZChild pofz
join fetch pofz.grantParentOfZChild where foo.someFeild = ?1")
我遇到的问题是有0个zChild条目然后我没有回到foo对象。我的物品都是正确的水合物,但显然我缺少应该存在的实体。
答案 0 :(得分:0)
想出来,问题是你需要一直向左连接。
所以查询应该看起来像这样。
@Query("select distinct foo from Foo foo
join fetch foo.parentItem pi
left join fetch pi.ZeroOrMoreChildren zChild
left join fetch zChild.parentOfZChild pofz
left join fetch pofz.grantParentOfZChild where foo.someFeild = ?1")