Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Hibernate数据检索改进。_Java_Hibernate_Hql - Fatal编程技术网

Java Hibernate数据检索改进。

Java Hibernate数据检索改进。,java,hibernate,hql,Java,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,它有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对象,但我必须调用这些对象中的每一个getEntityBentityBgetEntityC来获取完整的对象,因此对于这种延迟加载,有太多的DB调用

提及:我不能覆盖映射

在(几年前)我使用JDBC之前,如果使用sql,我会做类似的事情,但是使用HQL,我可以在一个查询中检索完整的entityA对象吗


谢谢大家!

您需要在“fetch”中使用,或者在条件或hql中使用,或者您可以在关系-lazy=false中设置或者在条件上,或者在hql中,或者您可以在关系上设置-lazy=false

这似乎类似。这工作正常…从EntityA entA left join fetch entA.entityB left join fetch entA.entityB.entityC中选择distinct entA entA entA left join fetch entA.entityB.entityC,其中entA.entityB.entityC.someValue='“+someValue+”";这似乎与类似。这工作正常…从EntityA entA左连接获取entA.entityB左连接获取entA.entityB.entityC中选择不同的entA,其中entA.entityB.entityC.someValue='“+someValue+”;