Hibernate 数据检索改进。
可能的重复:
我可以使用 HQL 预先加载属性吗?
我会尝试通过抽象真实场景来综合问题。
我有 EntityA ,它有 EntityB 作为成员并且是延迟加载的。
EntityB 拥有成员 EntityC
我现在所做的不是很理想
select distinct entA from EntityA entA ,EntityB entB, EntityC entC
where entA.ent_B_ID = entB.id and entB.ent_C_ID = entC.id and entC.someValue ='x'
这将检索所有 entityA 对象,但我必须调用每个对象这些对象 getEntityB 和 entityB getEntityC 上的对象具有完整的对象,因此对此延迟加载的数据库调用过多。
提及:我无法覆盖映射。
之前(几年前)我使用 JDBC 并使用 sql 我会做类似的事情,但是使用 HQL 我可以在 1 个查询中检索完整的 entityA 对象吗?
谢谢你!
Possible Duplicate:
Can I eager load a property using HQL?
I will try to synthesize the issue by abstracting the real scenario.
I have EntityA which has EntityB as member and is lazily loaded.
EntityB has as well as member EntityC
What I do now is not very optimum
select distinct entA from EntityA entA ,EntityB entB, EntityC entC
where entA.ent_B_ID = entB.id and entB.ent_C_ID = entC.id and entC.someValue ='x'
This will retrieve all entityA objects but I have to call on each of these objects getEntityB and on entityB getEntityC to have the full object ,so too many DB calls for this lazy loading.
Mention:I can't override mappings.
Before (years ago) I used JDBC and there with sql I would have done something similar but with HQL can I retrieve full entityA objects in 1 query ?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在“fetch”或标准或 hql 中使用,或者您可以在关系上设置-lazy=false
You need to use in "fetch" or on the criteria or in the hql or you can set on the relation - lazy=false