-->
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.  [ 4 posts ] 
Author Message
 Post subject: Clés Composées, jointures prb présence 2nd requete
PostPosted: Fri Nov 16, 2007 10:01 am 
Newbie

Joined: Fri Feb 23, 2007 7:13 pm
Posts: 3
Hibernate version: 3.1.3

Data Base: Ingres 2.5

Bonjour à toutes Zé à tous...

Au moyen d'Hibernate j'essaye de mapper 2 tables stdtask et staskb.
Je me sers de l'API de critéria. Tous les résultats sont rammenés mais la requete générée ne me convient pas.

Comme le montre les fichiers de mapping la relation

stdtask ----> staskb est de type <one-to-many>
et
stdtask<---- staskb est de type <many-to-one>

Code:


  <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="mapping">
   <class
      name="simat.mco.persistance.persistanceobject.gamme.entities.StdtaskSelectionGamme"
      table="stdtask">
      
      <meta attribute="sync-DAO">false</meta>
      <id name="Id" type="string" column="cde">
         <generator class="assigned" />
      </id>

      <many-to-one name="fstdtec" insert="false" update="false" fetch="join"
         class="simat.mco.persistance.persistanceobject.gamme.entities.FStdtec"
         column="cde" unique="true" not-found="ignore"/>


      
      <bag name="staskb" fetch="join" inverse="true" batch-size="101">
         <key >
            <column name="stdtask_cde" not-null="true"/>
         </key>
         <one-to-many 
            class="simat.mco.persistance.persistanceobject.gamme.entities.StaskbSelectionGamme" />
      </bag>

      <property name="LegendCde" column="legend_cde" type="string"/>
      
      <property>...</property>
   
   </class>
</hibernate-mapping>


Code:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="mapping">
   <class
      name="simat.mco.persistance.persistanceobject.gamme.entities.StaskbSelectionGamme"
      table="staskb">
      <meta attribute="sync-DAO">false</meta>
      <composite-id >
         <key-property name="StdtaskCde" column="stdtask_cde"
            type="string" />
         <key-property name="BudDatFr" column="bud_dat_fr"
            type="date"  />
         <key-property
            name="LorCde" column="lor_cde" type="string" />
      </composite-id>
   <many-to-one name="stdtask" insert="false" update="false"
         class="simat.mco.persistance.persistanceobject.gamme.entities.StdtaskSelectionGamme"
         column="stdtask_cde" />
   </class>

</hibernate-mapping>


En sortie, malgré la jointure entre stdtask et staskb, une autre requete est faite sur staskb au moment d'accéder aux propriétés des entités staskb.
En plus dans la 2nd requête je ne comprends pas pourquoi il répète deux fois de suite les même champs?

Code:
Hibernate:
    select
        first 101 this_.cde as cde2_2_,
        this_.legend_cde as legend2_2_2_,
        this_.taskt_cde as taskt3_2_2_,
        this_.verb_cde as verb4_2_2_,
        this_.net_ind as net5_2_2_,
        this_.dsc as dsc2_2_,
        this_.tsk_ctg as tsk7_2_2_,
        this_.renov_ind as renov8_2_2_,
        this_.stock_ind as stock9_2_2_,
        this_.indtskgqgn as indtskgqgn2_2_,
        fstdtec2_.stdtask_cde as stdtask1_8_0_,
        fstdtec2_.cicattec as cicattec8_0_,
        staskb1_.stdtask_cde as stdtask1_1_1_,
        staskb1_.bud_dat_fr as bud2_1_1_,
        staskb1_.lor_cde as lor3_1_1_
    from
        stdtask this_
    inner join
        f_stdtec fstdtec2_
            on this_.cde=fstdtec2_.stdtask_cde
    inner join
        staskb staskb1_
            on this_.cde=staskb1_.stdtask_cde
    where
        lowercase(this_.cde) like ?
Hibernate:
    select
        staskb0_.stdtask_cde as stdtask1_1_,
        staskb0_.bud_dat_fr as bud2_1_,
        staskb0_.lor_cde as lor3_1_,
        staskb0_.stdtask_cde as stdtask1_1_0_,
        staskb0_.bud_dat_fr as bud2_1_0_,
        staskb0_.lor_cde as lor3_1_0_
    from
        staskb staskb0_
    where
        staskb0_.stdtask_cde in (
            ?, ?, ?, ?, ?, ?
        )


Merci d'avance

Frédéric


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 17, 2007 4:15 am 
Beginner
Beginner

Joined: Thu Nov 15, 2007 11:27 am
Posts: 34
Peux tu mettre le code qui génére ces requetes?


Top
 Profile  
 
 Post subject: Génération des requêtes
PostPosted: Sat Nov 17, 2007 6:44 am 
Newbie

Joined: Sat Nov 17, 2007 6:42 am
Posts: 1
Location: France
Je travaille sous windows.

J'ai essayé de créer le fichier contenant les requêtes SQL créant une table.

J'ai créé une varaible d'environnement Hibernate = ".;D:\hibernate-3.2\lib\ant-1.6.5.jar;D:\hibern...." contenant le lib de hibernate-3.2

J'ai écrit le fichier de mapping D:\hibernate-3.2\mapping.xml suivant :
____________________
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>

<class name="Event" table="EVENTS">
<id name="id" column="EVENT_ID">
<generator class="increment"/>
</id>
<property name="date" type="timestamp" column="EVENT_DATE"/>
<property name="title"/>
</class>

</hibernate-mapping>
____________________

J'ai lancé la commande suivante :

D:\hibernate-3.2>java -cp HIBERNATE org.hibernate.tool.hbm2ddl.SchemaExport --output=D:\hibernate-3.2\my_schema.ddl D:\hibernate-3.2\mapping.xml

Voici le résultat :

Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/tool/hbm2ddl/SchemaExport

Y a-t-il quelqu'un qui sait pourquoi ? il me serait de grande aide. Merci


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 19, 2007 9:07 am 
Beginner
Beginner

Joined: Thu Nov 15, 2007 11:27 am
Posts: 34
org.hibernate.tool...

As tu les "hibernate tools" dans ton path? (ca doit etre un jar)
Ca ne semble pas etre un probleme hibernate, mais juste un probleme de lancement d'une classe java.


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