如何让 Hibernate FetchProfile 加载层次结构中的深层子对象
我和 Hibernate 社区中的某人有同样的问题:FetchProfiles 。
出于性能原因,我在数据模型中有如下关系:
...C -[FetchType.LAZY]-> D -> [FetchType.LAZY] -> E
使用 FetchProfile 我可以用 C 急切地加载 D,但我不知道如何急切地加载 E。我知道我可以使用内部联接成功使用 NamedQuery,但是我不知道如何使用 FetchProfile 来做到这一点,这真的让我很烦恼。尝试 FetchProfile 的示例(任何其他内容都会在时间的迷雾中丢失):
@FetchProfile(name = "cwithDAndE", fetchOverrides = {
@FetchProfile.FetchOverride(entity = C.class, association = "dByCId", mode = FetchMode.JOIN),
@FetchProfile.FetchOverride(entity = D.class, association = "eByDId", mode = FetchMode.JOIN)
})
我为会话启用 FetchProfile 并成功使用 session.get,没有错误,并且 C 和 D 已填充 - E 仍然是惰性的且未填充。在绝望中,我记得尝试用点符号表示从 C 向下的关联。我只能找到深度为 1 的示例。
这是我知识中的一个强迫症类型的空白,需要填补!
预先感谢您的任何帮助。
I have the same question as someone posted in the Hibernate Community: FetchProfiles.
For performance reasons I have a relationship in the data model as follows:
...C -[FetchType.LAZY]-> D -> [FetchType.LAZY] -> E
Using FetchProfile I can eagerly load D with C, but I can't figure out how to eagerly load E. I know I can successfully use a NamedQuery using inner joins, but it really bugs me that I can't work out how to do it using FetchProfile. An example of an attempted FetchProfile (anything else is lost in the mists of time):
@FetchProfile(name = "cwithDAndE", fetchOverrides = {
@FetchProfile.FetchOverride(entity = C.class, association = "dByCId", mode = FetchMode.JOIN),
@FetchProfile.FetchOverride(entity = D.class, association = "eByDId", mode = FetchMode.JOIN)
})
I enable the FetchProfile for the session and successfully use a session.get with no error and C and D populated - E is still lazy and unpopulated. In desperation I remember trying a dot notation for the association from C downwards. I can only find examples that have a depth of one.
This is an OCD type gap in my knowledge that needs filling!
Thanks in advance for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你有一个 A 对象,其中包含一个 B 对象,又包含一个 C 对象。默认情况下,它们是
A类:
B类:
ADao类:
你会得到A填充B填充C。这是一个非常基本的解决方案,您可以构建一个 Dao 方法,以获取配置文件列表作为参数。
You have a A obj containing a B obj, containing a C obj. By default they are
A class:
B class:
ADao class:
you will get A filled with B filled with C. This is a very basic solution, you can build a Dao method taking a list of fetch profile as argument.