FETCH JOIN最大深度? [英] FETCH JOIN maximum depth?
问题描述
JOIN FETCH entity1.collection1.collection2 //两个OneToMany关系
但是:
org.hibernate.HibernateException:命名查询错误:[...]
是因为它太深,还是因为无法以这种方式获取集合的集合?如果这是相关的,我的最大提取深度为3。
我可以同时从另一侧开始三JOIN FETCH:
JOIN FETCH entity3 .entity2.entity1 //两个ManyToOne关系
不知何故,我在JPA规范或Hibernate中找不到任何东西docs,这会限制这个子句的深度。
集合
的类型。而集合
没有 collection2
字段。这就是我对这些问题的理由。
您必须创建一个明确的连接集合:
从Entity1中选择e e
left join fetch e.collection1 as c1
left join fetch c1.collection2 as c2
请注意,这会产生笛卡尔积,因此可能会返回大量的行。还要注意,只有两个集合中的一个至少是一个集合才可能。如果他们都是行李,Hibernate在执行查询时会抛出异常。
W was trying to fetch join over three levels:
JOIN FETCH entity1.collection1.collection2 // two OneToMany relations
but got:
org.hibernate.HibernateException: Errors in named queries: [...]
Is it because it was too deep, or because a collection of collections cannot be fetched this way? My max fetch depth is 3, if this is relevant.
I can, at the same time, do a triple JOIN FETCH starting from the other side:
JOIN FETCH entity3.entity2.entity1 // two ManyToOne relations
Somehow I cannot find anything in JPA specification, or in Hibernate docs, that would limit the depth of this clause.
collection1
is of type Collection
. And a Collection
doesn't have a collection2
field. That's how I reason about those kind of queries.
You must the create an explicit join over the collection:
select e from Entity1 e
left join fetch e.collection1 as c1
left join fetch c1.collection2 as c2
Note that this will produce a cartesian product, and thus petentially returns a huge number of rows. Also note that it will only be possible if one of the two collections at least is a set. If they're both bags, Hibernate will throw an exception when executing the query.
这篇关于FETCH JOIN最大深度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!