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.  [ 2 posts ] 
Author Message
 Post subject: association with oneself ???
PostPosted: Thu Oct 05, 2006 12:07 pm 
Newbie

Joined: Thu Oct 05, 2006 11:54 am
Posts: 2
Hi everybody,

My problem is very simple :
- I have many objects (Entity class)
- each Entity can be associated with others Entities

Actually, I would like to have a base that looks like :

*********
* Entity *
*********
* id *
* name *
* ...etc...*
* ****** *

***************
* Entities_Links *
***************
* entity_id1 *
* entity_id2 *
* ****** *******

I then write the following hibernate mapping :

<hibernate-mapping>
<class name="Entity" table="ENTITY">
<id name="idBD" column="IDBD">
<generator class="native"/>
</id>

<set name="entities" table="ENTITIES_LINKS">
<key column="IDBD"/>
<many-to-many column="IDBD" class="Entity"/>
</set>
</class>
</hibernate-mapping>


And I get the following error :
Initial SessionFactory creation failed.org.hibernate.MappingException: Repeated column in mapping for collection: Entity.entities column: IDBD


I suppose hibernate is not able to directly create an association from one class to itself.
Then how can this be done ???

Thanxs a lot for your help,
Regards,
Steve


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 05, 2006 12:47 pm 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
Both your column names in the join table(ENTITIES_LINKS) are the same(IDBD). You need to give a separate name for each of the columns in the table. Make your mapping something like this.

Code:
<set name="entities" table="ENTITIES_LINKS">
<key column="IDBD1"/>
<many-to-many column="IDBD2" class="Entity"/>
</set>
</class>


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