views:

28

answers:

0

Hi, I'm having a hard time trying to clone a complex C# object persisted with NHibernate.
The object has a deeply nested structure with lots of children objects organized in ILists, but it is completely self contained, without references to other persisted entities.
What I've tried to do so far is to deep clone the object through serialization and deserialization, and then set all the Id properties of the cloned object to zero, in order to persist the result as an independent NHibernate record.
However, when saving the new object I'm getting an error that apparently shouldn't be there:

NHibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing.

I'm not able to figure out what's wrong, since the new object doesn't reference any independently persisted object and looks well at an eye inspection.

Also, any other idea for cloning a complex NHibernate object would be of great help!