-->
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: Can use map's key column same as many-to-many column?
PostPosted: Thu Jun 03, 2004 11:58 am 
Newbie

Joined: Sat Nov 01, 2003 12:35 pm
Posts: 11
Hi,
I have a class C having a map of Product with prduct's id as map's key like the following:

<map name="products" table="C_PRODUCTS" cascade="none">
<key column="C_ID"/>
<index column="PRODUCT_ID" type="string" />
<many-to-many column="PRODUCT_ID" class="Product"/>
</map>

When running program, there is error saying "repeated column declaration". For such mapping, how to do it?

Thanks,
Rice


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 2:55 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
CAn't do that. You have to merge it at the java level

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 8:53 pm 
Newbie

Joined: Sat Nov 01, 2003 12:35 pm
Posts: 11
What is meant by "doint it at Java Level"? It means I have to change my Java model? My current work-around is to change the collection to set, instead of map. Any other way?

Regards,
Rice


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 08, 2004 3:45 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Keep map and manually set
map.put(product.getId(), product);
or even better do a addProduct() method doing the job.

If you want a map, you will need an extra index column.

Your replacement with set seems to prove you don't really need an index afterall.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 08, 2004 12:47 pm 
Newbie

Joined: Mon Jun 07, 2004 10:46 am
Posts: 2
Quote:
If you want a map, you will need an extra index column.

Why is this so ? This seems like a very natural thing to do, that is, use the foreign key as the key to an internal map. I posted a similar question myself.

Quote:
Your replacement with set seems to prove you don't really need an index afterall.

I disagree. Not being able to do this directly, i.e. having to provide a separate parallel Map leads to redundancy, while using only Set leads to inefficient searches.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 5:54 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
kktec wrote:
Quote:
If you want a map, you will need an extra index column.

Why is this so ? This seems like a very natural thing to do, that is, use the foreign key as the key to an internal map. I posted a similar question myself.

Actually we must stay compliant with the Java freedom.
In pure Java code, you can set the index different from the product id. That's why Hibernate mandate the use of an extra index column. I understand you use case, but you should understand the Java way to best understand some Hibernate design decisions.

_________________
Emmanuel


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.