简体   繁体   English

FETCH JOIN最大深度?

[英]FETCH JOIN maximum depth?

W was trying to fetch join over three levels: W试图通过三个级别获取联接:

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. 如果相关,我的最大获取深度为3。

I can, at the same time, do a triple JOIN FETCH starting from the other side: 同时,我可以从另一侧开始执行三重JOIN FETCH:

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. 不知何故,我在JPA规范或Hibernate文档中找不到任何限制此子句深度的内容。

collection1 is of type Collection . collection1的类型为Collection And a Collection doesn't have a collection2 field. Collection没有collection2字段。 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. 如果它们都是包,那么Hibernate在执行查询时会抛出异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM