I've tried creating fresh session and using SaveOrUpdateCopy to get back clone. But the problem I see now (maybe a bug until someone can prove that this is by design) that SaveOrUpdateCopy do not create clones of collections.
>From documentation: This method copies the state of the given object onto the persistent object with the same identifier. If there is no persistent instance currently associated with the session, it will be loaded. The method returns the persistent instance. If the given instance is unsaved or does not exist in the database, NHibernate will save it and return it as a newly persistent instance. Otherwise, the given instance does not become associated with the session As I understand it should respect cascades. But it is not. Bug? It will be awesome if both Copy and Merge will work properly. This would help ppl start using NHibernate in desktop applications without troubles. On Jun 19, 5:23 am, Tyler Burd <[email protected]> wrote: > I have a need to deep copy an object graph and have the copy routine follow > the cascade settings in the class's mapping file. Basically, for every > collection and property marked cascade="<anything>", I need to also deep copy > that object, preferably resetting the primary key property to the > unsaved-value for that type. Here is a simple example of what I'm trying to > do: > > //load AggRoot #1 > var myAggRoot = session.Load(typeof(AggRoot), 1); > // assertion: myAggRoot.Id == 1 > // assertion: myAggRoot.PropertyWithCascade.Id == 2 > // assertion: myAggRoot.PropertyWithNoCascade.Id == 3 > > var copiedAggRoot = SomeDeepyCopyRoutine(myAggroot); > //the properties configured to cascade are deep-copied and their PK's are set > to 0. > // assertion: copiedAggRoot.Id == 0 > // assertion: copiedAggRoot.PropertyWithCascade.Id == 0 > > //the properties NOT configured to cascade are not deep-copied. > // assertion: myAggRoot.PropertyWithNoCascade.Id == 3 > > Has anyone solved a similar problem? I've googled with no luck. So far I'm > copying all aggregate roots by hand, but that is tedious and error-prone. > > Thanks! > -tyler --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
