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.  [ 5 posts ] 
Author Message
 Post subject: Collection with nested collections - Possible?
PostPosted: Mon Feb 28, 2005 1:43 pm 
Newbie

Joined: Wed Nov 12, 2003 4:57 pm
Posts: 14
Location: New York City
Hibernate version: 2.1.8 (but would switch to 3.0 if it can handle this)

Lets say I have three Objects:


Code:

public class Product {
     private List salesChannels;
}


public class SalesChannel {
     private List prices;

}


public class Price {
     private long price;
}


As you can see, Product has a List of sales channels and each sales channel has a list of prices. Is it possible to map this in hibernate? Near as I can tell, it is impossible to have a collection of collections. Is there a good work around?

Thanks,

Ethan Schreiber


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 28, 2005 2:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Not possible. Use an intermediate object.


Top
 Profile  
 
 Post subject: intermediate object
PostPosted: Tue Mar 15, 2005 2:14 pm 
Newbie

Joined: Wed Nov 12, 2003 4:57 pm
Posts: 14
Location: New York City
Im not quite sure what you mean by intermediate object. Does this mean that if I want to save a Product, SalesChannel and Price I would need to do somethind like this:

Code:
   session.save(product);
   
   Iterator salesChannels = product.getSalesChannels().iterator();

   while (salesChannels.hasNext()) {
      SalesChannel salesChannel = (SalesChannel) salesChannels.next();
      session.save(salesChannel);
   }



Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 3:30 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Ah sorry, missread your question.

You can of course map a class A containing a Set<B> where class B contains a Set<C>

what you can not do is map a Set<Set<X>>


Top
 Profile  
 
 Post subject: it worked
PostPosted: Tue Mar 15, 2005 5:31 pm 
Newbie

Joined: Wed Nov 12, 2003 4:57 pm
Posts: 14
Location: New York City
thanks for your help Michael!


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