-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problème avec une collection
PostPosted: Thu Aug 30, 2007 6:19 am 
Newbie

Joined: Fri Apr 20, 2007 8:40 am
Posts: 4
Bonjour,

J'ai une table avec une table de lien, j'utilise HibernateTools pour le mapping qui me génère les fichiers suivant :

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 30 ao?t 2007 10:34:54 by Hibernate Tools 3.2.0.b9 -->
<hibernate-mapping>
    <class name="com.cnes.regates.preparation.modeleDonnees.DAONoeud" table="noeud" catalog="regates">
        <comment></comment>
        <id name="idNoeud" type="int" unsaved-value="0">
            <column name="idNOEUD" />
            <generator class="identity" />
        </id>
        <property name="nom" type="string">
            <column name="nom" length="20" not-null="true">
                <comment></comment>
            </column>
        </property>
        <set name="DAONoeudNoeudsForIdNoeudpere" inverse="true">
            <key>
                <column name="idNOEUDPere" not-null="true">
                    <comment></comment>
                </column>
            </key>
            <one-to-many class="com.cnes.regates.preparation.modeleDonnees.DAONoeudNoeud" />
        </set>
        <set name="DAONoeudNoeudsForIdNoeudfils" inverse="true">
            <key>
                <column name="idNOEUDFils" not-null="true">
                    <comment></comment>
                </column>
            </key>
            <one-to-many class="com.cnes.regates.preparation.modeleDonnees.DAONoeudNoeud" />
        </set>
    </class>
</hibernate-mapping>


Et

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 30 ao?t 2007 10:34:54 by Hibernate Tools 3.2.0.b9 -->
<hibernate-mapping>
    <class name="com.cnes.regates.preparation.modeleDonnees.DAONoeudNoeud" table="noeud_noeud" catalog="regates">
        <comment></comment>
        <composite-id name="id" class="com.cnes.regates.preparation.modeleDonnees.DAONoeudNoeudId">
            <key-property name="idNoeudpere" type="int">
                <column name="idNOEUDPere" />
            </key-property>
            <key-property name="idNoeudfils" type="int">
                <column name="idNOEUDFils" />
            </key-property>
        </composite-id>
        <many-to-one name="DAONoeudByIdNoeudfils" class="com.cnes.regates.preparation.modeleDonnees.DAONoeud" update="false" insert="false" fetch="select">
            <column name="idNOEUDFils" not-null="true">
                <comment></comment>
            </column>
        </many-to-one>
        <many-to-one name="DAONoeudByIdNoeudpere" class="com.cnes.regates.preparation.modeleDonnees.DAONoeud" update="false" insert="false" fetch="select">
            <column name="idNOEUDPere" not-null="true">
                <comment></comment>
            </column>
        </many-to-one>
    </class>
</hibernate-mapping>


Mon problème est que lorsque je select DAONoeud les collections DAONoeudNoeudsForIdNoeudpere et DAONoeudNoeudsForIdNoeudfils ne sont jamais remplis. Quelqu'un aurrait une idée du pourquoi ? Merci.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 30, 2007 9:06 am 
Newbie

Joined: Fri Apr 20, 2007 8:40 am
Posts: 4
Bon j'ai trouvé où ce situe mon problème.

En faite lorsque HibernateTools génère le mapping pour une table de lien pointant sur la même table (dans mon cas la table de lien lie la table noeud à elle même) il met, je pense, les ids comme ils viennent. En locurence pour la liste des noeuds pere il me met l'id du noeud pere et pour la liste des noeuds fils il me met l'id du noeud fils.

Il me fallait donc inverser ces ids dans le fichier DAONoeud.hbm.xml comme suit :

Quote:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 30 ao?t 2007 10:34:54 by Hibernate Tools 3.2.0.b9 -->
<hibernate-mapping>
<class name="com.cnes.regates.preparation.modeleDonnees.DAONoeud" table="noeud" catalog="regates">
<comment></comment>
<id name="idNoeud" type="int" unsaved-value="0">
<column name="idNOEUD" />
<generator class="identity" />
</id>
<property name="nom" type="string">
<column name="nom" length="20" not-null="true">
<comment></comment>
</column>
</property>
<set name="DAONoeudNoeudsForIdNoeudpere" inverse="true">
<key>
<column name="idNOEUDFils" not-null="true">
<comment></comment>
</column>
</key>
<one-to-many class="com.cnes.regates.preparation.modeleDonnees.DAONoeudNoeud" />
</set>
<set name="DAONoeudNoeudsForIdNoeudfils" inverse="true">
<key>
<column name="idNOEUDPere" not-null="true">
<comment></comment>
</column>
</key>
<one-to-many class="com.cnes.regates.preparation.modeleDonnees.DAONoeudNoeud" />
</set>
</class>
</hibernate-mapping>


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