Unfortunately no.  Just OID and Version.



On 25 September 2015 at 11:37, Gunnar Liljas <gunnar.lil...@gmail.com>
wrote:

> Do you have another property on Person that can be changed explicitly
> instead, perhaps a ModifiedOn timestamp, thereby triggering version
> increment?
>
> 2015-09-25 16:27 GMT+02:00 Peter V <pvhey...@gmail.com>:
>
>> But is there an elegant way to just force NHibernate to update the
>> version number of both toPerson and fromPerson when TransferProperty is
>> called?
>>
>> Locking fromPerson as dirty doesn't do it (I guess because nothing
>> actually changed), and I'm trying to avoid modifying the class mapping (the
>> regression test effort of doing so would be huge because there is so much
>> other code that references it).
>>
>> Thanks,
>> Peter
>>
>>
>>
>>
>>
>> On Friday, September 25, 2015 at 1:35:40 AM UTC-4, Gunnar Liljas wrote:
>>>
>>> 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 <pvhe...@gmail.com>:
>>>
>>>> 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 <pvhe...@gmail.com>:
>>>>>
>>>>>> 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 nhusers+u...@googlegroups.com.
>>>>>> To post to this group, send email to nhu...@googlegroups.com.
>>>>>> 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 nhusers+u...@googlegroups.com.
>>>> To post to this group, send email to nhu...@googlegroups.com.
>>>> 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 nhusers+unsubscr...@googlegroups.com.
>> To post to this group, send email to nhusers@googlegroups.com.
>> 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 a topic in the
> Google Groups "nhusers" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/nhusers/-Q8Q7_8jyI4/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> nhusers+unsubscr...@googlegroups.com.
> To post to this group, send email to nhusers@googlegroups.com.
> 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 nhusers+unsubscr...@googlegroups.com.
To post to this group, send email to nhusers@googlegroups.com.
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to