FETCH JOIN 最大深度?
W 试图获取超过三个级别的连接:
JOIN FETCH entity1.collection1.collection2 // two OneToMany relations
但是得到:
org.hibernate.HibernateException: Errors in named queries: [...]
是因为它太深了,还是因为无法以这种方式获取集合的集合?我的最大获取深度是 3,如果这是相关的。
同时,我可以从另一侧开始执行三重 JOIN FETCH:
JOIN FETCH entity3.entity2.entity1 // two ManyToOne relations
不知何故,我在 JPA 规范或 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
collection1
的类型为Collection
。Collection
没有collection2
字段。这就是我对此类查询的推理方式。您必须在集合上创建显式联接:
请注意,这将产生笛卡尔积,因此可能返回大量行。另请注意,只有当两个集合中至少有一个是集合时才有可能。如果它们都是包,Hibernate 在执行查询时会抛出异常。
collection1
is of typeCollection
. And aCollection
doesn't have acollection2
field. That's how I reason about those kind of queries.You must the create an explicit join over the collection:
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.