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.  [ 3 posts ] 
Author Message
 Post subject: set and many-to-many
PostPosted: Thu Jan 19, 2006 1:30 pm 
Regular
Regular

Joined: Wed Sep 21, 2005 1:37 pm
Posts: 53
Location: Montpellier - France
Hello, I want to make 3 tables :

USERS
+ user_id
+ name
...

GROUPS
+ group_id
+ name
...

and the association table used to add each user to multiple groups :
GROUP_MEMBERS
+ group_id
+ user_id

Hibernate version: 3.1

Mapping documents:

For 'User' :
Code:
<class name="UserBMP" table="USERS" node="user">
<id name="primaryKey" column="user_id" type="java.lang.String" node="@user_id" unsaved-value="null"/>
<timestamp name="lastModifiedDate" column="last_modified" node="@last_modified"/>
<property name="password" column="password" type="java.lang.String" not-null="true" lazy="true" node="@password"/>
<set name="groups" table="GROUP_MEMBERS" lazy="true" node="groups" embed-xml="false" cascade="persist,save-update" inverse="true">
<key column="user_id"/>
<many-to-many class="GroupBMP" node="@group_id"  embed-xml="false"/>
</set>
</class>


For 'Group' :
Code:
<class name="GroupBMP" table="GROUPS" node="group">
<id name="primaryKey" column="group_id" type="java.lang.String" node="@group_id" unsaved-value="null"/>
<timestamp name="lastModifiedDate" column="last_modified" node="@last_modified"/>
<property name="permissions" column="permissions" type="byte" not-null="true" lazy="true" node="@permissions"/>
<set name="members" table="GROUP_MEMBERS" lazy="true" node="users" embed-xml="false" cascade="persist,save-update">
<key column="group_id"/>
<many-to-many class="UserBMP" node="@user_id"  embed-xml="false"/>
</set>
</class>


Full stack trace of any exception that occurs:
Quote:
Caused by: org.hibernate.DuplicateMappingException: Duplicate collection role mapping GroupBMP.members
at org.hibernate.cfg.Mappings.addCollection(Mappings.java:123)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2023)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:1998)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:361)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:275)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:146)
at org.hibernate.cfg.Configuration.add(Configuration.java:385)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 19, 2006 4:34 pm 
Regular
Regular

Joined: Wed Sep 21, 2005 1:37 pm
Posts: 53
Location: Montpellier - France
In the class 'Mappings', the method 'addCollection' put the new collection definition using its role as key in the map of global collections.

I think that in 'Collection', the method 'getRole' return null. Why ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 4:44 am 
Regular
Regular

Joined: Wed Sep 21, 2005 1:37 pm
Posts: 53
Location: Montpellier - France
It was the setter, not implemented. Logs are not very explicit.


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