Hello,
I'm trying to map a relatively simple parent-children (Invoice-InvoiceEntry) scenario in NHibernate. Here are some parts of my mapping files:
from Invoice.hbm.xml
<set name="InvoiceEntries" table="InvoiceEntries" inverse="true" cascade="all-delete-orphan" lazy="false">
<key column="InvoiceID" />
<one-to-many class="Jobflow.Models.Entities.InvoiceEntry, Jobflow" />
</set>
from InvoiceEntry.hbm.xml
<many-to-one name="Invoice" class="Jobflow.Models.Entities.Invoice, Jobflow" column="InvoiceID" not-null="true" lazy="false" />
from Invoice.cs
private ISet<IInvoiceEntry> _invoiceEntries = new HashedSet<IInvoiceEntry>();
public virtual ISet<IInvoiceEntry> InvoiceEntries
{
get { return _invoiceEntries; }
set { _invoiceEntries = value;}
}
What happens is that when I save an invoice everything is fine. A new record is inserted into both tables. The value in column InvoiceID in the InvoiceEntries table is the same as the ID column in the Invoices table. However, when I try to load the invoice from the repository via NHibernate I get the following error:
NHibernate.ObjectNotFoundException: No row with the given identifier exists[Jobflow.Models.Entities.InvoiceEntry#55]
55 is indeed the correct ID in the Invoices table and the correct InvoiceID in the InvoiceEntries table. However, it seems like NHibernate might be looking for the InvoiceEntries PK which is EnvoiceEntryID instead.
Can anybody help me with this?