-->
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.  [ 5 posts ] 
Author Message
 Post subject: component + all-delete-orphan
PostPosted: Mon Oct 03, 2005 4:55 pm 
Regular
Regular

Joined: Thu May 12, 2005 10:12 am
Posts: 71
Location: Buenos Aires, Argentina
After a demo with 0.9.1 version we're back on track setting up the latest build. Last time I reported strange behaviour, mostly with all-delete-orphan. Some of these exceptions were our codes fault, but there is one that has been driving me crazy for hours now.

The problem I'm experiencing is with a component. Here is a trimmed version of my mapping file:


Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
   xmlns="urn:nhibernate-mapping-2.0" 
   namespace="SAFJP.SICI.Model.Carteras"
   assembly="SAFJP.SICI.Model.Carteras"
   default-access="field">
   
    <class
      name="Recepcion"
      table="T_Recepcion">
           
      <id
         name="mId"
         column="recepcion_ID"
         type="Int32"
         unsaved-value="-1">
         <generator class="native" />
      </id>
<component
         name="mBalanceCalculado"
         class="BalanceGeneral">
         <component
            name ="Cuentas"
            access="property"
            class="ICuentaCollection" >
            <bag
               name="InternalCuentas"
               table="T_Cuenta_Balance_Calculado"
               order-by="Cuenta_ID"
               cascade="all-delete-orphan"
               batch-size="50"
               lazy="true"
               access="property">
               <key column="Recepcion_ID" />
               <many-to-many column="Cuenta_ID" class="ICuenta"/>
            </bag>
         </component>
      </component>
   </class>
</hibernate-mapping>

?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
   xmlns="urn:nhibernate-mapping-2.0" 
   namespace="SAFJP.SICI.Model.Carteras"
   assembly="SAFJP.SICI.Model.Carteras"
   default-access="field">

    <class
      name="ICuenta"
        table="T_Cuenta"
        batch-size="20">
       
        <id
         name="Id"
         column="cuenta_ID"
         type="Int32"
         unsaved-value="-1"
         access="property">
         <generator class="native" />
      </id>
      
      <discriminator
         column="tipoCuenta_Class"
         type="string"
         length="2"
      />
<component
         name="mBalance"
         class="BalanceGeneral">
         <component
            name ="Cuentas"
            access="property"
            class="ICuentaCollection" >
            <bag
               name="InternalCuentas"
               table="T_Cuenta_Balance"
               order-by="Cuenta_ID"
               cascade="all-delete-orphan"
               batch-size="30"
               lazy="true"
               access="property">
               <key column="Recepcion_ID" />
               <many-to-many column="Cuenta_ID" class="ICuenta"/>
            </bag>
         </component>
      </component>
<component
         name ="SubCuentas"
         access="property"
         class="ICuentaCollection" >
         <bag
            name="mInternalCuentas"
            table="T_Cuenta"
            order-by="codigoCuenta_ID"
            cascade="all-delete-orphan"
            batch-size="20"
            lazy="true">
            <key column="cuentaPadre_ID" />
            <one-to-many class="ICuenta"/>
         </bag>
      </component>
   </class>
</hibernate-mapping>


The problem could be that I'm actually making a copy of a Property of one object to the BalanceGeneral like this. The code looks like this:

Code:
Dim balance As BalanceGeneral

balance = recepcion.BalanceGeneral.CrearCopia()

For Each cuentaSAFJP As Cuenta In balance.Cuentas
   Me.CalcularMontoCuenta(recepcion, cuentaSAFJP)
Next

balance.RecalcularCuentasBalance()
recepcion.BalanceGeneralCalculado= balance


I've been folowing nhibernate code and it complians because in method UpdateUnreachableCollection it basically trying to save the old ICuentaCollection that was part of the recepcion.BalanceGeneralCalculado that existed before.

What puzzeles me is that I never set the component up. It got constructed automatically by NH. So I guess my question is how do I replace the component that NH created with a new one.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 04, 2005 10:34 am 
Regular
Regular

Joined: Thu May 12, 2005 10:12 am
Posts: 71
Location: Buenos Aires, Argentina
Any news...I just want to know if what I'm doing is wrong. Basically what I have is a component that cotains a Bag with delete-all-orphan, inside another component. After the class is set up I replace the top level component with a new object and hibernate complains about not being able to delete the first component.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 04, 2005 12:13 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
To avoid the error you should re-use the collection instead of making a copy of it and then replacing the original instance. Or you can stop using the delete-orphan functionality, of course :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 04, 2005 1:59 pm 
Regular
Regular

Joined: Thu May 12, 2005 10:12 am
Posts: 71
Location: Buenos Aires, Argentina
Thanks. I fixed it avoiding the all-delete-orphamn. But it seems odd nonetheless. Are you sure this is not a bug and it is wanted functionality?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 04, 2005 2:31 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Well, my argument #1 in this case is that Hibernate developers did it this way, so that's how it works... Another argument is that this check is needed to prevent bugs, since for delete-orphan to function the collection needs to know which table to delete the elements from, and for this to work the collection needs to be referenced by a persistent object.


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