-->
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.  [ 1 post ] 
Author Message
 Post subject: Mapping many-to-many
PostPosted: Thu Nov 24, 2005 10:35 am 
Newbie

Joined: Thu Nov 24, 2005 10:25 am
Posts: 1
Bonjour à tous. J'ai un petit souci lors de la persitence d'objets.
J'ai un table TypeDePlat et une table Plat.
Un plat peut avoir plusieurs type de plat (nombre indéfini).
J'ai donc décidé de créer une table complémentaire "typeplatcollection" qui contient les liens entre les deux tables.

Voici le fichier .hbm :
Code:
      <class name="....Plats" table="plats">
         <id name="idHh" column="id_plat" type="long">
            <generator class="increment"/>
         </id>
         <property name="name"/>
         <property name="description"/>
         <property name="price" type="float"/>
           <set name="typeDePlats" table="typeplatcollection" cascade="all-delete-orphan">
                  <key column="id_plat" />
                    <many-to-many column="id_typeplat"
                       class="....TypePlat"
                       unique="true" outer-join="true"/>
           </set>
         
      </class>
   
      <class name="....TypePlat" table="typeplat">
         <id name="idHh" column="id_typeplat" type="long">
            <generator class="increment"/>
         </id>
         <property name="name"/>
         <property name="description"/>
      </class>

Lorsque je crée un nouveau plat avec des types de plats, tout est OK.
Lorsque je delete, tout est OK
Lorsque je modifie :
Si je supprime un type de plat et que j'en remet un nouveau, c'est OK.
Si j'ajoute un nouveau type de plat, là j'ai une erreur :
org.hibernate.NonUniqueObjectException:a different object with the same identifier value was already associated with the session

Dans mon code java, je supprime l'ancien "Set" et j'en recrée un nouveau avec les type de plats ajouté.

Je ne trouve pas la solution, pourriez-vous m'aider ?

Merci.




Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.