-->
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.  [ 1 post ] 
Author Message
 Post subject: Transitive Many-to-One Mappings
PostPosted: Wed Apr 06, 2005 7:20 pm 
Newbie

Joined: Wed Apr 06, 2005 6:52 pm
Posts: 1
What is the most efficient way to deal with transitive one-to-many mappings? For example, one A has many Bs, and one B has many Cs, and I want a set of all Cs associated with a certain A.

So conceptually I want:

Code:
Set s = instanceOfA.getBs().getCs();


My most recent attempt looked like this:
Code:
    Iterator it = instanceOfA.getBs().iterator();
    while (it.hasNext()){
      if (s == null){
        s = ((B) it.next()).getCs();
      }
      else{
        s.addAll(((B) it.next()).getCs());
      }
    }

It seems like there must be a better way to do it than adding all those sets together.

The other way that came to mind to do it was to do a join in HQL, but I think that is to be avoided:

Code:
     String queryString = "select c from C as c join c.B as b join b.A as a where a.property = 'Value'";
      Iterator it = sess.iterate(queryString);


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

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.