Graham:
inverse="true" and cascade="save-update" appear to be in conflict with
each other. inverse="true" means "i am not the object responsible for
saving the contents of the collection so when someone flushes a
transaction, please ignore my contents" and cascade="save-update"
means "when I am flushed, persists the contents of my collection".
AFAIK, if you simply remove the invserse="true" and leave the
cascasde="..." you can persist only the IAsset instance and it should
all work, no?
Also, I would be interested to know what the conditions (performance)
were that lead you to 'revert' to this more 'manual' way of persisting
your records to your DB; I suspect that there may be a better way to
get the benefits of NHib persisting your object graph and also meet
your performance demands rather than your having to essentially 'walk
the object graph yourself, persisting things in the correct dependency
order' since by doing this you are (IMHO) losing alot of the value
that something like NHib brings to the table for you.
HTH,
-Steve B.
On Nov 28, 11:47 am, Graham Bunce <[EMAIL PROTECTED]> wrote:
> 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
-~----------~----~----~----~------~----~------~--~---