-->
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] Classe association
PostPosted: Thu Aug 18, 2005 9:27 am 
Newbie

Joined: Wed Aug 10, 2005 6:26 am
Posts: 8
Hibernate version: 3

salut, g lu beaucoup d'exemple sur le mapping d'association (2 classes) mais pas trop sur les classes associations (3 classes)

En fait voici le schema relationnel:

caractéristique(numC, ...) // eg. 1-couleur, 2-poids, 3-taille, ...
produit(numP, ...) // eg. 1-voiture, 2-velo
carac_prod(numP, numC, valeur) //eg. 1-1-noire, 1-2-1000, 2-1-rouge, 2-2-15

J'ai le probleme suivant:
avant je modelisais carac_produit comme étant un element composite de produit, avec un many-to-one vers Caractéridtique

Ca marche bien sauf que maintenant je veux mapper carac-produit comme une association, donc j'ecrit:

Quote:

<hibernate-mapping>

<class name="dao.CaracProduit" table="CARAC_PRODUIT">


<composite-id >
<key-property name="numProduit" column="numP" />
<key-property name="numCarac" column="numCarac" />
</composite-id>

<property name="valeur" type="string" >
<column name="valeur" sql-type="varchar(50)" not-null="true"/>
</property>

<many-to-one name="produit"
column="numP"
insert="false"
update="false"
not-null="true"
/>
<many-to-one name="carac" outer-join="true"
column="numCarac"
insert="false"
update="false"
not-null="true"
/>


</class>

</hibernate-mapping>



et voici produit:
[/quote]
<hibernate-mapping>

<class name="dao.Produit" table="PRODUIT" >

<id name="numProduit" type="int" unsaved-value="null">
<column name="numProduit" sql-type="int(11)" not-null="true"/>
<generator class="increment" />
</id>

...

<set name="listCaract" table="CARAC_PRODUIT" lazy="true" >
<key column="numP"/>
<one-to-many class="dao.CaracProduit" />
</set>

<!-- mapping avec un composite-element:
<set name="listCaract" table="CARAC_PRODUIT" lazy="true" inverse="true" >
<key column="numP"/>
<composite-element class="dao.CaracProduit" >
<property name="valeur" column="valeur" />
<many-to-one class="dao.Caracteristique" name="carac" column="numCarac" outer-join="true" />
</composite-element>
</set>
-->

</class>

</hibernate-mapping>
Quote:

et caracteristique:



<hibernate-mapping>

<class name="dao.Caracteristique" table="CARACTERISTIQUE">

<id name="numCarac" type="int" unsaved-value="null" >
<column name="numCaracteristique" sql-type="int(11)" not-null="true"/>
<generator class="increment" />
</id>

<property name="libelleCarac" type="string" >
<column name="libelleCarac" sql-type="varchar(30)" not-null="true"/>
</property>

<set name="listCaract" table="CARAC_PRODUIT" lazy="true" >
<key column="numCarac"/>
<one-to-many class="dao.CaracProduit" />
</set>

</class>

</hibernate-mapping>
Quote:

g besoin de
* pouvoir lister les carac_produit et les caracteristique d'1 produit (en 1 requete --> outer-join=true)

* lister les carac-produit (valeurs) d'un caracteristique

* quand je crée un produit, je dois pouvoir également sauver ses carac-produit


pour l'instant il me retourne null quand je liste les carac-produit

voici un extrait du log DEBUG mode:


Quote:

15:15:58,902 DEBUG DefaultLoadEventListener:143 - loading entity: [dao.Produit#1]
15:15:58,902 DEBUG DefaultLoadEventListener:208 - entity found in session cache
15:15:58,902 DEBUG DefaultInitializeCollectionEventListener:42 - initializing collection [dao.Produit.listCaract#1]
15:15:58,902 DEBUG DefaultInitializeCollectionEventListener:47 - checking second-level cache
15:15:58,902 DEBUG DefaultInitializeCollectionEventListener:59 - collection not cached
15:15:58,902 DEBUG Loader:1426 - loading collection: [dao.Produit.listCaract#1]
15:15:58,902 DEBUG AbstractBatcher:290 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
15:15:58,918 DEBUG SQL:324 - select listcaract0_.numP as numP2_, listcaract0_.numCarac as numCarac2_, listcaract0_.numP as numP1_, listcaract0_.numCarac as numCarac1_, listcaract0_.valeur as valeur9_1_, listcaract0_.numP as numP9_1_, listcaract0_.numCarac as numCarac9_1_, caracteris1_.numCaracteristique as numCarac1_0_, caracteris1_.libelleCarac as libelleC2_5_0_ from CARAC_PRODUIT listcaract0_ inner join CARACTERISTIQUE caracteris1_ on listcaract0_.numCarac=caracteris1_.numCaracteristique where listcaract0_.numP=?
Hibernate: select listcaract0_.numP as numP2_, listcaract0_.numCarac as numCarac2_, listcaract0_.numP as numP1_, listcaract0_.numCarac as numCarac1_, listcaract0_.valeur as valeur9_1_, listcaract0_.numP as numP9_1_, listcaract0_.numCarac as numCarac9_1_, caracteris1_.numCaracteristique as numCarac1_0_, caracteris1_.libelleCarac as libelleC2_5_0_ from CARAC_PRODUIT listcaract0_ inner join CARACTERISTIQUE caracteris1_ on listcaract0_.numCarac=caracteris1_.numCaracteristique where listcaract0_.numP=?
15:15:58,918 DEBUG AbstractBatcher:378 - preparing statement
15:15:58,918 DEBUG IntegerType:59 - binding '1' to parameter: 1
15:15:58,918 DEBUG AbstractBatcher:306 - about to open ResultSet (open ResultSets: 0, globally: 0)
15:15:58,918 DEBUG Loader:718 - result set contains (possibly empty) collection: [dao.Produit.listCaract#1]
15:15:58,918 DEBUG CollectionLoadContext:85 - uninitialized collection: initializing
15:15:58,934 DEBUG Loader:405 - processing result set
15:15:58,934 DEBUG Loader:410 - result set row: 0
15:15:58,934 DEBUG IntegerType:86 - returning '10' as column: numCarac1_0_
15:15:58,934 DEBUG IntegerType:86 - returning '1' as column: numP1_
15:15:58,934 DEBUG IntegerType:86 - returning '10' as column: numCarac1_
15:15:58,934 DEBUG AbstractBatcher:313 - about to close ResultSet (open ResultSets: 1, globally: 1)
15:15:58,934 DEBUG AbstractBatcher:298 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
15:15:58,934 DEBUG AbstractBatcher:416 - closing statement
eeeee dao.CaracProduit
15:15:58,934 DEBUG JDBCTransaction:132 - rollback
15:15:58,949 DEBUG JDBCContext:278 - before transaction completion
15:15:58,949 DEBUG SessionImpl:372 - before transaction completion
15:15:58,949 DEBUG JDBCTransaction:173 - re-enabling autocommit
15:15:58,949 DEBUG JDBCTransaction:143 - rolled back JDBC Connection
15:15:58,949 DEBUG JDBCContext:283 - after transaction completion
15:15:58,949 DEBUG SessionImpl:403 - after transaction completion
15:15:58,949 DEBUG SessionImpl:269 - closing session
15:15:58,949 DEBUG ConnectionManager:317 - closing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
15:15:58,965 DEBUG JDBCContext:283 - after transaction completion
15:15:58,965 DEBUG SessionImpl:403 - after transaction completion
null
15:15:58,965 DEBUG SessionImpl:269 - closing session



est ce que l'erreru vient du mapping???


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.