tags:

views:

24

answers:

0

Hi,

Using Fluent nHibernate on my database.

I'm perplexed as to why one of my .Update statements seems to create new data and leave the old data in the table as orphaned rows without a key. Take this as an example: the problematic object is a "MetaData" object which has a many-to-one relationship with a "Page" object (a Page can have many MetaData objects).

So if I have the following row of MetaData for Page 1

Id    Page_Id    name    content
1     1          test1   test1

I then have some functionality which allows users to add more name/content pairs to the page metadata. This seems to work fine: stepping through the code at the end of the process the Page object has the expected number of MetaData objects with the expected values. So let's say the user adds one more row of values test2, test2. After calling a session.Update with that Page object, my table looks like this:

Id    Page_Id    name    content
1     null       test1   test1
2     1          test1   test1
3     1          test2   test2

In other words nHibernate has saved the new data, but it's left the old value in the table with a null page_Id. This happens if there are multiple old rows in the table - they all get dupliacted and orphaned in this manner.

I've checked that the Page object is as expected when it gets updated, and I've made sure my update method isn't being called twice. Can someone point me as to what the problem here might be?

Cheers, Matt