Steve,

Thanks for your input... I was doing what you said, but in looking
into it I noticed something else. I changed that and I fixed the
problem. For reference (and feedback) the method was:

        public IAssetContent AddContent(IContent content)
        {
            //Create an asset content, add it to both ends of its
relationships then register it with the repository
            IAssetContent assetContent = new AssetContent(this,
content);
            _assetContents.Add(assetContent);
            content.Assets.Add(assetContent);

            Helper.Repository.Add(assetContent);

            return assetContent;
        }

What caused the problem was "content.Assets.Add(assetContent);". This
was a hangover from my last NHibernate project where I was told to
always remove an object from any relationship it resides in, otherwise
you will get "deleted object will be resaved by cascade". I applied
that rule to creating my relationships and it appears that if I do, I
get the problem. (btw the constructor of AssetContent does set the
object references as you describe).

On your second point, I had changed my mappings to cascade="none"
optimistic-lock="false" for performance reasons. When I changed back
to cascade="save-update", I still needed the:

repository.Add(newAsset);
repository.Add(newContent);
repository.Add(newAssetContent);

in the correct order. If I moved the add of AssetContent of sequence
(first in the list) then the system will crash with a SQL Foreign Key
exception (AssetContent against Content). If I put it second in the
list, back at the end or remove it altogether it actually causes a
StaleObjectStateException with the value
"AssetContent#00000000-0000-0000-0000-000000000000".

So I'm still confused. Thanks for the advice so far but Im obviously
missing something fundamental. What is it?

ps: Latest Mappings to reproduce above:
    <bag name="AssetContents" table="AssetContents" inverse="true"
cascade="save-update" >
      <key column="AssetId" on-delete="cascade" />
      <one-to-many class="AssetContent" />
    </bag>
--~--~---------~--~----~------------~-------~--~----~
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