-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Retrieve collections using a join
PostPosted: Tue Dec 16, 2008 6:00 am 
Newbie

Joined: Sun Nov 26, 2006 12:53 pm
Posts: 13
Hello, I've read many posts and the documentation, but I cannot find a easy solution to an easy problem.

I have one class, for example BigFooObject, that collects many LittleDetail:

Code:
   <class name="BigFooObject" table="big_foo_table" 
      <id name="uid" column="uid">
         <generator class="assigned"/>
      </id>
      <property name="prop1" />
      <set name="option" fetch="join" inverse="true">
         <key column="bigfooref"/>
         <one-to-many class="LittleDetail"/>
      </set>
   </class>

   <class name="LittleDetail" table="little_detail_table" >
      <id name="uid" column="uid">
         <generator class="assigned"/>
      </id>
      <many-to-one name="bigfooref" class="BigFooObject"/>
   </class>


Notice the fetch="join" in the set definition, I have the same question asked in this post without a real solution: http://forum.hibernate.org/viewtopic.php?t=988028&postdays=0&postorder=asc&highlight=set+fetch+join&start=15

It seems to me that Hibernate works in this way, for example retrieving BigFooObject #123:

Code:
select * from BigFooObject where uid = 123;


then redoes "select" to get all the information regarding LittleDetails found as reference in BigFooObject (do not tell me about lazy initialization,please, this is not the point):


Code:
select * from LittleDetail where uid = 3;
select * from LittleDetail where uid = 56;
select * from LittleDetail where uid = 129;
...


Is there a way to create a mapping that does something very simple like this SINGLE query, having all the stuff correctly initialized in the appropriate pojos?
Code:
select bfo.*, ld.* from BigFooObject as bfo, LittleDetail as ld where bfo.uid = ld.bigfooref and bfo.uid = 123;


Thank you in advance.
Mirko


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2008 7:02 am 
Newbie

Joined: Fri Jun 08, 2007 5:21 pm
Posts: 1
Hi Mirko, could you post the hql select query? Should be better you show the complete test case.

p.s.: anyway, Hibernate seems run the right way becouse your wished select:
Code:
select bfo.*, ld.* from BigFooObject as bfo, LittleDetail as ld where bfo.uid = ld.bigfooref and bfo.uid = 123;


should be replayed foreach retrived child, replicating the already trasmitted data (BigFooObject object).

Ciao,
Fabio


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.