Reputation:
I have 2 POCOs mapped as such:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="APPayment" table="APPayments">
<id name="PaymentId">
<generator class="guid" />
</id>
<many-to-one name="Invoice" class="APInvoice" cascade="none"
column="InvoiceId" index="ixPaymentInvoice" not-null="true" />
</class>
<class name="APInvoice" table="APInvoices">
<id name="InvoiceId">
<generator class="guid" />
</id>
<bag name="Payments" inverse="true" cascade="none" >
<key column="PaymentId" foreign-key="fkInvoicePayments" />
<one-to-many class="APPayment" />
</bag>
</class>
</hibernate-mapping>
For some reason I cannot fathom, I am generating duplicate foreign keys on my APPayments
table:
fk9cdfbf509640182e
fkinvoicepayments
I think this is causing some other problems with saving the object relationships as well. Did I misconfigure a mapping? What do I need to do to get this working properly?
Upvotes: 2
Views: 779
Reputation: 52745
Here's your problem:
<key column="PaymentId" ...
The key
to the collection should be the InvoiceId.
Upvotes: 2