-->
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 et many-to-many
PostPosted: Thu Jan 19, 2006 1:35 pm 
Regular
Regular

Joined: Wed Sep 21, 2005 1:37 pm
Posts: 53
Location: Montpellier - France
Bonjour à tous, je dois faire une association avec 2 tables :

USERS
+ user_id
+ name
...

GROUPS
+ group_id
+ name
...

et créer la table pour l'association permettant d'attribuer plusieurs groupes à chaque utilisateur :
GROUP_MEMBERS
+ group_id
+ user_id

Hibernate version: 3.1

Mapping documents:

Pour '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>


Pour '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:36 pm 
Regular
Regular

Joined: Wed Sep 21, 2005 1:37 pm
Posts: 53
Location: Montpellier - France
Dans la classe 'Mappings', la méthode 'addCollection' ajoute la nouvelle spécification de la collection en utilisant son rôle comme clé.

Je pense que la clé est nulle et que dans 'Collection', la méthode 'getRole' doit retourner 'null'. Mais je vois pas comment résoudre cela.


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

Joined: Wed Sep 21, 2005 1:37 pm
Posts: 53
Location: Montpellier - France
Bon, ca venait du setter non implémenté mais il faut avouer que les logs sont trompeurs.


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.