views:

27

answers:

0

Hi,

I was just wondering if it was normal for NHibernate to always update the item that are on the "many" side of a one-to-many mapping i.e. the items in the bag, even when there was no change. I have this:

 <class name="PrimaryClass" table="PrimaryTable" lazy="false">
    <id name="Id" column="id">
      <generator class="assigned" />
    </id>
    <bag name="OneToManyClass" inverse="true" lazy="false" table="OneToManyTable" cascade="none">
      <key>
        <column name="foreignKeyId" />
      </key>
      <one-to-many class="className" />
    </bag>
  </class>

NHibernate issues a select for the object of the PrimaryClass that I am trying to save and then issues a select for each item in the bag, by the foreignKeyId. Now, I only get updates issues to the PrimaryTable when something something changed in the PrimaryClass object. However, I'm getting updates issues to the OneToManyTable all the time. This is an example of the statements issued when I have two items in the collection and there was no changes made to any objects.

Note that all objects being saved or updated have assigned ids with SaveOrUpdateCopy being applied to them:

SELECT ... FROM   PrimaryTable WHERE  id = 1

// selects foreignKeyId 10 and 11
SELECT ... FROM   OneToManyTable WHERE  foreignKeyId = 1  


UPDATE ClientProductLicense WHERE  id = 10
UPDATE ClientProductLicense WHERE  id = 11