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!