-->
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: many to many problem
PostPosted: Sat Mar 18, 2006 11:44 pm 
Newbie

Joined: Wed Dec 28, 2005 4:54 pm
Posts: 10
I have 2 tables TOMO and MOVIMIENTO and the join table MOVIMIENTO_TOMO.

I use a bag to represent the many to many problem.

Here is the mapping I'm using

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">

    <class name="MetadatosCuba.Negocio.Entidades.Movimiento.Movimiento, MetadatosCuba.Negocio.Entidades" table="MOVIMIENTO" schema="MODULOCUBA">
       
        <id name="Id" type="Int32" unsaved-value="0">
            <column name="ID"  />
            <generator class="sequence">
               <param name="sequence">SEQ_MOVIMIENTO</param>
            </generator>   
        </id>     
       
        <bag name="Tomos" inverse="true" lazy="true" cascade="save-update" table="MOVIMIENTO_TOMO">
            <key column="IDMOVIMIENTO"/>               
            <many-to-many class="MetadatosCuba.Negocio.Entidades.Tomos.Tomos, MetadatosCuba.Negocio.Entidades" column="IDTOMO"/>
        </bag>       
       
 
       
    </class>
</hibernate-mapping>



Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">

    <class name="MetadatosCuba.Negocio.Entidades.Tomos.Tomos, MetadatosCuba.Negocio.Entidades" table="TOMO" schema="MODULOCUBA">
       
        <id name="Id" type="Int32" unsaved-value="0">
         <column name="ID"  />
         <generator class="sequence">
            <param name="sequence">SEQ_TOMO</param>
         </generator>
     </id>
       
               
       
       
       
        <bag name="Movimientos" lazy="true" cascade="save-update" table="MOVIMIENTO_TOMO">
            <key> <column name="IDTOMO"  not-null="true" /> </key>             
           <many-to-many class="MetadatosCuba.Negocio.Entidades.Movimiento.Movimiento, MetadatosCuba.Negocio.Entidades" column="IDMOVIMIENTO"/>
        </bag>         
       
                 
    </class>
</hibernate-mapping>



The problem is that when I use this code
Movimiento move = new Movimiento()
session.Save(move);
Tomo tomo = new Tomo();
session.Save(tomo);
tomo.Movimientos.Add(move);
move.Tomos.Add(tomo);
session.SaveOrUpdateCopy(tomo);
session.SaveOrUpdateCopy(move);

NHibernate deletes all the members of my join table and put the last MOVIMIENTO of my TOMO

What can I do???? Please help


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.