-->
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: how: many-to-many with composite key attribute
PostPosted: Tue Nov 20, 2007 8:44 am 
Beginner
Beginner

Joined: Fri Jun 23, 2006 6:40 pm
Posts: 25
Hello guys

i understand and i did without problem a relation many-to-many between 2 classes but when each has one varibale how pk/id

like
http://www.hibernate.org/hib_docs/v3...ional-join-m2m
Code:
<class name="Person">
    <id name="id" column="personId">
        <generator class="native"/>
    </id>
    <set name="addresses" table="PersonAddress">
        <key column="personId"/>
        <many-to-many column="addressId"
            class="Address"/>
    </set>
</class>

<class name="Address">
    <id name="id" column="addressId">
        <generator class="native"/>
    </id>
    <set name="people" inverse="true" table="PersonAddress">
        <key column="addressId"/>
        <many-to-many column="personId"
            class="Person"/>
    </set>
</class>

my problem is when one class has its pk like composite key and the other no
i saw this link
http://www.hibernate.org/hib_docs/v3...key-manytomany
but it a little confuse for me

this is my hbm.xml pk declarations

Code:
<hibernate-mapping
>
    <class
        name="com.modelo.entidades.CabeceraAlmacen"
        table="CabeceraAlmacen"
        discriminator-value="CABALM"
    >
        <composite-id
            name="almacenPK"
[b]            class="com.modelo.entidades.AlmacenPK"[/b]
        >
                     <key-property
                        name="idnumero"
                        type="java.lang.String"
                        column="idnumero"
                        length="6"
                />

                     <key-property
                        name="serie"
                        type="java.lang.String"
                        column="serie"
                        length="3"
                />

        </composite-id>


and the other class

Code:
<hibernate-mapping
>
    <class
        name="com.modelo.entidades.ArticuloNoAuto"
        table="ArticuloNoAuto"
    >

        <id
            name="idArticuloNoAuto"
            column="idArticuloNoAuto"
            type="java.lang.String"
            length="20"
        >
            <generator class="assigned">
             </generator>
        </id>


maybe some friendly member can share some code or show me how
resolve this situation
many-to-many with composite key attribute

thanks in advanced
__________________

_________________
kill your pride, share your knowledge with all


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 09, 2007 12:25 pm 
Newbie

Joined: Sun Apr 04, 2004 4:22 am
Posts: 7
Code:
<class
        name="com.modelo.entidades.CabeceraAlmacen"
        table="CabeceraAlmacen"
        discriminator-value="CABALM"
    >
        <composite-id
            name="almacenPK"
[b]            class="com.modelo.entidades.AlmacenPK"[/b]
        >
                     <key-property
                        name="idnumero"
                        type="java.lang.String"
                        column="idnumero"
                        length="6"
                />

                     <key-property
                        name="serie"
                        type="java.lang.String"
                        column="serie"
                        length="3"
                />

        </composite-id>
     
       <set name="articuloNoAutos" table="CabeceraAlmacenArticuloNoAuto" lazy="true|false" cascade="..." inverse="true|false">
           <key>
              <column name="idnumero">
              <column name="serie">
           </key>
           <one-to-many class="com.modelo.entidades.CabeceraAlmacenArticuloNoAuto"/>
       </set>




    <class
        name="com.modelo.entidades.ArticuloNoAuto"
        table="ArticuloNoAuto"
    >

        <id
            name="idArticuloNoAuto"
            column="idArticuloNoAuto"
            type="java.lang.String"
            length="20"
        >
            <generator class="assigned">
             </generator>
        </id>
       <set name="cabeceraAlmacens" lazy="true|false" cascade="" inverse="true|false">   
         <key column="idArticuloNoAuto">
         <one-to-many class="com.modelo.entidades.CabeceraAlmacenArticuloNoAuto"/>
       </set>

_________________
Thanks for rating this posting!!!


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.