-->
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: Probleme avec many-to-many et insert
PostPosted: Sat May 05, 2007 4:23 pm 
Newbie

Joined: Sat May 05, 2007 4:19 pm
Posts: 5
Hibernate version: 3

Bonjour,

j'ai un probleme avec mon association m à n que voici:

J'ai une table Person, une language et une person_language qui contient juste les deux clés etrangeres.

Au niveau des object java, j'ai Person qui a une List de language,
L'object Language qui a une list de Person.

Voici les mapping:

Languages.hbm.xml
Code:
<hibernate-mapping>
    <class name="com.unisys.r4egov.eaw.spring.bo.Languages" table="languages" catalog="eaw1">
        <comment></comment>
        <id name="id" type="string">
            <column name="ID" length="3" />
            <generator class="assigned" />
        </id>
        <property name="name" type="string">
            <column name="NAME" length="20">
                <comment></comment>
            </column>
        </property>
<bag name="reqPersonsAs" table="persons_languages" outer-join="true"  cascade="all" lazy="false">
            <key>
                <column name="LANGUAGE_ID" length="3" not-null="true">
                    <comment></comment>
                </column>
            </key>
            <many-to-many entity-name="com.unisys.r4egov.eaw.spring.bo.ReqPersonsA">
                <column name="PERSON_ID" not-null="true">
                    <comment></comment>
                </column>
            </many-to-many>
        </bag>    </class>
</hibernate-mapping>


person.hbm.xml
Code:
<hibernate-mapping>
    <class name="com.unisys.r4egov.eaw.spring.bo.ReqPersonsA" table="req_persons_a" catalog="eaw1">
        <comment></comment>
        <id name="id" type="int" unsaved-value="0">
            <column name="ID" />
            <generator class="identity" />
        </id>
        <property name="name" type="string">
            <column name="NAME" length="200">
                <comment></comment>
            </column>
        </property><bag  name="languageses" outer-join="true" inverse="true" table="persons_languages" cascade="all"  lazy="false" >
            <key>
                <column name="PERSON_ID" not-null="true" >
                    <comment></comment>
                </column>
            </key>
            <many-to-many entity-name="com.unisys.r4egov.eaw.spring.bo.Languages" >
                <column name="LANGUAGE_ID" length="3" not-null="true" >
                    <comment></comment>
                </column>
            </many-to-many>
        </bag>
    </class>
</hibernate-mapping>


Code:


Qd j'insère une personne qui a comme langue le francais, c'est ok, j'ai bien dans ma table person_language l'id de la person avec la langue fr.
Par contre qd j'insere une deuxieme person avec comme langue aussi le francais, et bien au lieu de rajouter une deuxieme entrée dans la table person_language, il me supprime la premiere et rajoute alors la deuxieme.

Voici le query sql généré:

Code:
Hibernate: insert into eaw1.req_persons_a (NAME) values (?)
Hibernate: select languages_.ID, languages_.NAME as NAME12_ from eaw1.languages languages_ where languages_.ID=?
Hibernate: insert into eaw1.eu_arrest_warrant (CENTRAL_ID, SIGNATURE_ID, PERSON_ID, DECISION_ID, SENTENCE_ID, LANGUAGE_ID, ISSUING_JUDICIAL_AUTHORITY_ID, ABSENTIA_ID, DATE, LEGAL_GARANTEES_D, OTHER_CIRCUMSTANCES_F, TOTAL_OFFENCES_E, FULL_DESCRIPTION_OFFENCES_E) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

Hibernate: delete from persons_languages where LANGUAGE_ID=?

Hibernate: insert into persons_languages (LANGUAGE_ID, PERSON_ID) values (?, ?)



Je ne comprends vraiment pas ce comportement, comment eviter ce delete pour pouvoir peupler correctement ma table person_languages,


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.