-->
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: Eager loading object with multiple sets
PostPosted: Wed Mar 14, 2007 8:42 pm 
Newbie

Joined: Sun Sep 24, 2006 7:33 pm
Posts: 2
Hello,

This question has been asked multiple times on this forum but nobody seems to have a clear answer.

I have a class (A) which has 3 sets of other classes (B, C and D) (one-to-many). These classes have a many-to-one relationship with another class (E).
Code:
        B
      /   \   
    /       \
  /           \
A - - - C - - - E
  \           /
    \       /
      \   /
        D

What I'm trying to accomplish is to load one object of class A and eagerly load all it's references to B, C and D which in their turn have to eagerly load all their references to E.

I've tried to solve this with a Criteria, but that seemed to be impossible. Then I tried this HQL statement:
Code:
from A a1
         left join fetch a1.B as b1                      
         left join fetch b1.e as e1
         left join fetch a1.C as c1
         left join fetch c1.e as e2
         left join fetch a1.D as d1
         left join fetch d1.e as e3
where a1.number = :number


This seems to work but it generates an enormous amount of overhead because of the cartesian product problem.

What I actually want to do is to instantiate the object of class A using 3 queries, one for each Set. However I haven't found a way to do this.

I'm also considering to keep my session open and use Hibernate.initialize on the Sets, but this will generate a lot of overhead to which is not something I want.

Can somebody help me with this problem?[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 15, 2007 4:35 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
If you can use bi-directionnal associations, between e and b, c, d, then you can only fetch b.e, c and d (if you populate c.e and d.e when you call setC and setD on e object).
I think there is no good solution to this problem because the modelisation will lead to a huge cartesian product by design.

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


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.