It is removed from toPerson as a side effect since the collection is mapped as inverse, and you change the Owner. But NHibernate has no way of knowing this.
Since Property really seems to be a full blown entity, maybe you can handle deletions of it explicity (with session.Delete), and thereby be able to set the cascade to not delete orphans. 2015-09-25 0:16 GMT+02:00 Peter V <[email protected]>: > Thanks, that's definitely a solution. > But I'd prefer not to have to clone it if there's another way -- my actual > Property class is a lot more complex than what I've shown here, and cloning > it may introduce some other issues. > > The thing is, even with RemoveProperty commented out, the property is > getting removed from fromPerson. > So I don't understand why the version of fromPerson isn't incremented. > > Peter > > > > On Thursday, September 24, 2015 at 5:15:42 PM UTC-4, Gunnar Liljas wrote: >> >> With RemoveProperty commented out, nothing is done with fromPerson, hence >> no version increment. >> >> I'm guessing the cascade "deletes" the property. >> >> Maybe instead of transferring you could remove the property from >> fromPerson and add a cloned property to toPerson. >> >> >> >> 2015-09-24 20:37 GMT+02:00 Peter V <[email protected]>: >> >>> I have the following NHibernate mapping: >>> >>> <class name="Person" proxy="Person" table="Person_"> >>> >>> <id name="OID" column="OID_" type="Guid"> >>> <generator class="guid.comb"/> >>> </id> >>> >>> <version name="Version" column="Version_"/> >>> >>> <set name="Properties" lazy="true" inverse="true" >>> cascade="all-delete-orphan"> >>> <key column="PersonOID_"/> >>> <one-to-many class="Property"/> >>> </set> >>> >>> </class> >>> >>> >>> And the following C# code: >>> >>> public class Property >>> { >>> public Person Owner; >>> } >>> >>> public class Person >>> { >>> private ISet _properties; >>> >>> public void AddProperty(Property property) >>> { >>> property.Owner = this; >>> _properties.Add(property); >>> } >>> >>> public void RemoveProperty(Property property) >>> { >>> property.Owner = null; >>> _properties.Remove(property); >>> } >>> } >>> >>> ... >>> >>> public void TransferProperty(Property p, Person fromPerson, Person >>> toPerson) >>> { >>> //fromPerson.RemoveProperty(p); >>> toPerson.AddProperty(p); >>> } >>> >>> >>> A call to TransferProperty results in the entity version for toPerson >>> getting incremented, but no change to the entity version for fromPerson. >>> >>> This is causing me a problem when multiple users call TransferProperty >>> at the same time -- because fromPerson version doesn't change, there is no >>> PersistenceException thrown when two users try to transfer property from >>> the same person at the same time. >>> >>> Any thoughts on the best way to modify this code so that calling >>> TransferProperty will increment the entity versions for both toPerson and >>> fromPerson??? >>> >>> Thanks in advance! >>> Peter >>> >>> P.S. I commented out the RemoveProperty call in TransferProperty, >>> because it was resulting in "ObjectDeletedException: deleted object would >>> be re-saved by cascade (remove deleted object from associations)". >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "nhusers" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To post to this group, send email to [email protected]. >>> Visit this group at http://groups.google.com/group/nhusers. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/nhusers. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "nhusers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/nhusers. For more options, visit https://groups.google.com/d/optout.
