-->
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: A Map collection having elements being Sets ?
PostPosted: Mon May 17, 2004 6:17 pm 
Regular
Regular

Joined: Thu Apr 29, 2004 5:08 pm
Posts: 56
Location: Montreal, Quebec, Canada
Hi,

I have these tables:

Code:
Component_Type
  id

Component
  id
  type_id

Version
  id
  component_id

Component_Dependency
  id
  base_version_id
  dependency_version_id

In other words, a component may have a set of dependent components. These can be of any type (from the Component_Type table).

I would like, in Object Oriented code, to do something like:
Set dependentComponentVersions = (Set)version.getDependencies().get( componentType );

This would return a set of dependent component versions, from a specific component versions. The set of dependent component versions would contains only dependent component versions of a certain type.

With Hibernate:
I can't see a way to use a map collection having sets as its elements.
I don't see how I could have my mapping files to accomplish what I just described

Is there a way? Any comments on the way we modelised this in the DB?

Thank you,

_________________
- Frank


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 17, 2004 6:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You can't map nested collections. You have to use an intermediate class if you want to do so.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 17, 2004 6:50 pm 
Regular
Regular

Joined: Thu Apr 29, 2004 5:08 pm
Posts: 56
Location: Montreal, Quebec, Canada
Well,

I know how I could return the complete list of dependent versions for a version....

Set dependentVersion version.getDependencies();

Having a Set mapped with "many-to-many" (or with an intermediate class)

But, then I would have to filter that set for component of the specific type I want. I would like to avoid this.

I would like version.getDependencies() to return a Map collection. The index would be a componentType object and the element would be a Set of DependentVersion objects (here is the intermediate class).

Is it possible to accomplish this with hibernate? Having a Map collection returning a Set of entities?

Thanks

_________________
- Frank


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 17, 2004 7:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
No, not possible. Hibernate managed Maps can contain only "value" elements or mapped entities, not Sets.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 17, 2004 8:06 pm 
Regular
Regular

Joined: Thu Apr 29, 2004 5:08 pm
Posts: 56
Location: Montreal, Quebec, Canada
Ok,

Do you have any suggestion for my specific case then?

How would you handle that situation? Should I use session.filter() to finally have a list of the dependent component versions of a specific type?

Any suggestion would help.

Thanks again for your quick replies,

_________________
- Frank


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 08, 2004 8:53 pm 
Regular
Regular

Joined: Thu Apr 29, 2004 5:08 pm
Posts: 56
Location: Montreal, Quebec, Canada
Quote:
You can't map nested collections. You have to use an intermediate class if you want to do so.


Yes, perfect. I'm now using a Class (and a hbm mapping) for every table in the relational model. This resolved everything and gives me more power at querying the information i need.

Since I have a surrogate key for every tables in the relational model, this was essential anyway.

_________________
- Frank


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.