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)