-->
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.  [ 4 posts ] 
Author Message
 Post subject: simple question regarding many-to-many association
PostPosted: Wed Feb 25, 2004 2:10 pm 
Regular
Regular

Joined: Fri Aug 29, 2003 12:48 pm
Posts: 63
Hi guys. I've got a very simple mapping question. I've got a many-to-many mapping in which children can belong to multiple parents. I'd like the parents to have a Map of children, indexed by name, instead of a simple set. My current mapping is:

Code:
<set name="fields" table="SECTION_FIELDS_TABLE" lazy="true">
  <key column="section_id"/>
  <many-to-many class="com.rhoworld.edc.model.Field" column="field_id"/>
</set>


How can I turn this into a map whose key values are the fields' name properties? I'm using hibernate-2.1. Thanks for any tips.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2004 2:19 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You'll have to set it manually (in you addChild() method actually, and create a different column, just as non related indexes.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2004 2:27 pm 
Regular
Regular

Joined: Fri Aug 29, 2003 12:48 pm
Posts: 63
You're suggesting that I should add a string column to the mapping table, and manually set the value when I add a new Field to the Section? I don't like that solution very much - it duplicates data that's already in the Field table. I'd rather manually maintain a map in the Section object than do that. But I'd much rather be able to tell hibernate to maintain said map for me :).

It would seem this wouldn't be an uncommon use case, nor a particularly difficult mapping to support. Does anyone else have a need for such a thing?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2004 6:50 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Can't do that, because your app can always put a different index in the map it will set.

_________________
Emmanuel


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