Hi.
I'm using NH 1.2.
I have an association (master/detail) mapped with the Set element. It's very simple:
Empresa.hbm.xml (master)
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Dominio" namespace="Dominio.Modelo">
<class name="Empresa">
<id name="Id">
<generator class="assigned" />
</id>
<property name="Nome" />
<set name="Notas" inverse="true">
<key column="IdEmpresa" />
<one-to-many class="NotaFiscal" />
</set>
</class>
</hibernate-mapping>
NotaFiscal.htm.xml (child)
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Dominio" namespace="Dominio.Modelo">
<class name="NotaFiscal" >
<id name="Id">
<generator class="assigned" />
</id>
<property name="Serie" />
<property name="Numero" />
<many-to-one name="Empresa" column="IdEmpresa" />
</class>
</hibernate-mapping>
To save and obj. "Empresa" with one "NotaFiscal" added I'm using the following code:
Code:
Empresa empresa = new Empresa();
empresa.Id = 2;
empresa.Nome = "xxxx";
NotaFiscal nota = new NotaFiscal();
nota.Id = 2;
nota.Serie = "PRE";
nota.Numero = 2;
nota.Empresa = empresa;
empresa.Notas.Add(nota);
NHHelper.Save(empresa); // Save and Flush
But when a look into the table "Empresa" and "NotaFiscal" just the first is saved!
Should I use the ISession.Save(nota) (without flush) before my Save(empresa)?
Thanks