I have a situation where I don't want the Version property updated or
incremented on a Parent entity if anyone adds a Child entity to the
Parent's Children collection.  I have the Parent's Children collection
property mapped with optimistic-lock="false" so that the
Parent.Version property stays the same if someone adds a Child entity
(Parent.Children.Add(child)) and saves the Parent entity (this assumes
that no modifications were made to any other properties of the Parent
entity).

However, whenever I save the Parent entity after adding a Child, the
Parent.Version value is incremented.  Is this the expected behaviour
of NHibernate?

I noticed that the unit test, CollectionNoVersion() in
NHibernate.Test.VersionTest.VersionFixture, which tests the optimistic-
lock="false" feature on a collection property does not call
SaveOrUpdate() or Update().  Instead, the method simply commits the
transaction and closes the session as follows:

        s = OpenSession();
        t = s.BeginTransaction();
        gavin = (Person) s.CreateCriteria(typeof(Person)).UniqueResult();
        new Task("Document", gavin);
        t.Commit();
        s.Close();

        Assert.AreEqual(1, gavin.Version);
        Assert.IsFalse(NHibernateUtil.IsInitialized(gavin.Tasks));

        <class name="Person">
                <id name="Name">
                        <generator class="assigned" />
                </id>
                <version name="Version"/>
                <bag name="Tasks"
                                inverse="true"
                                cascade="all-delete-orphan"
                                optimistic-lock="false">
                        <key column="person"/>
                        <one-to-many class="Task"/>
                </bag>
        </class>

I am using Spring.NET to manage transactions in our applications as
the majority of our existing code outside of the persistence layer
uses System.Transactions.TransactionScope.  Spring.NET does a good job
of managing NHibernate's ITransaction and Microsoft's TransactionScope
class for us, so that we don't have to expose NHibernate outside of
the persistence layer.

Any advice is greatly appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to