Hello.
I'm trying to build a one way navigation graph but I'm having some problems with the persistence of an associated collection. Here's my scenario (simplified for easier understanding):
public class Factura{
Int32 _id;
Int32 _version;
//other simple properties
IList<ItemFactura> _entradas;
}
public class ItemFactura
{
Int32 _id;
Int32 _version;
//more properties and a collection of components
//but it's not important here so I've removed it
}
now, I've got something like this on my hbm files:
Factura.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
xmlns="urn:nhibernate-mapping-2.2"
schema="dbo"
assembly="SRA.Mercados.Facturacao"
namespace="SRA.Mercados.Facturacao">
<class name="Factura"
table="Factura" lazy="false">
<id name="Id" column="IdFactura" unsaved-value="0">
<generator class="identity" />
</id>
<version name="Version" column="Version"
type="int"/>
<!-- other properties removed -->
<bag name="_entradas" access="field" lazy="false" cascade="all">
<key column="IdFactura" />
<one-to-many class="ItemFactura"/>
</bag>
</class>
</hibernate-mapping>
and the itemfactura.hbm looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
xmlns="urn:nhibernate-mapping-2.2"
schema="dbo"
assembly="SRA.Mercados.Facturacao"
namespace="SRA.Mercados.Facturacao">
<class name="ItemFactura"
table="ItemFactura" lazy="false">
<id name="Id" column="IdItemFactura" unsaved-value="0">
<generator class="identity" />
</id>
<version name="Version" column="Version"
type="int"/>
<property name="Desconto" column="Descontos" />
<!--other properties removed -->
</class>
</hibernate-mapping>
Now the question: to propagate an insert do I need to make my relationship a two way relationship? My current problem is that when nhibernate propagates the insertion it won't use the <key> element defined inside the <bag> element of the factura mapping element.
I mean, when I try to insert a factura on the db, NH will generate this SQL:
2008-01-28 12:14:01,271 [8] DEBUG NHibernate.SQL - INSERT INTO dbo.ItemFactura (Version, Descontos) VALUES (@p0, @p1); select SCOPE_IDENTITY(); @p0 = '1', @p1 = '0'
The problem is that it won't insert the IdFactura column when generating the sql for inserting the itemfactura entry on the table.
so, what am I doing wrong?
thanks.
|