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.

Reply via email to