-->
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.  [ 6 posts ] 
Author Message
 Post subject: Yo! - object graph loading!
PostPosted: Mon May 31, 2004 10:33 am 
Newbie

Joined: Tue Mar 23, 2004 10:40 am
Posts: 9
Location: toronto
Hi,

Ive read a couple of posts but Im still confused.

If I have tables A->B->C (A has a set of Bs, B has a set of Cs). With UseOuterJoin=false and lazyLoading=true.

Ive tried the query:
"from A as a
left join fetch a.B as b
left join fetch b.C"

It doesnt throw an exception but returns A's with no B's attached.

I recall reading that you can only have one left join fetch in your query. I also read other people suggesting the above query (which has two fetches). Its also quite possible that my settings are screwed.

So to recap my question is how can I get an object graph of A's with B's and C's attached.


Top
 Profile  
 
 Post subject: Re: Yo! - object graph loading!
PostPosted: Mon May 31, 2004 11:19 am 
Senior
Senior

Joined: Sun Oct 26, 2003 5:05 am
Posts: 139
I'd normally just have a set of B's defined on A and a set of C's defined in B in the hibernate mapping file. Then with lazy-loading set to true, when I load A, I can just eagerly get b's and c's (so if you only want A, you don't have to waste time getting the B's and C's. You usually end up doing something like

a.getBs().size();

and for loading all the b's and c's, you do

Code:
Iterator i = a.getBs().iterator();
while( i.hasNext() ) {
    B b = (B) i.next();
    b.getCs().size();
}


That's all I do anyway.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 31, 2004 1:33 pm 
Newbie

Joined: Tue Mar 23, 2004 10:40 am
Posts: 9
Location: toronto
Well Im using the dto's on the client side after the session is closed. I think the pattern is called thread local session.

I need to load the 1-to-many's explicitly in a query.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 31, 2004 2:02 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you can't, only one collection can be fetch in a query

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 31, 2004 3:23 pm 
Newbie

Joined: Tue Mar 23, 2004 10:40 am
Posts: 9
Location: toronto
Thank you.

It seems like a strange limitation - is there plans to allow this in future versions?

_________________
Be happy :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 31, 2004 5:43 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
hi kedaar,
not as strange as you think, of course this feature would "seem" powerfull.
But you only have to think of the consequence: a cartesian product on the resultset Hibernate core need to analyse to fill your object graph.

Don't worry;)

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.