It sounds like you have multiple Document objects representing the same Document entity. This is likely due to "new-ing" up the objects during a postback. Your new objects are not associated with an NHibernate session and you want to attach the objects to a session so that you can persist changes. For example:
Doc1 -> Doc2 -> Doc1'
where Doc1 and Doc1' are different objects, but have the same identifier.
You have a few potential solutions.
#1 Create an identity map to use when re-creating the objects. Basically this is a hashtable of ID vs. object. Before creating each document object, check if you've already created it. If so, use the same physical object.
#2 Collect up all the IDs, start a NH session, load the Document objects using NH, update the Document objects with the posted back data, commit the transaction, then close the session.
#3 Use ISession.SaveOrUpdateCopy() to get a new copy of your object that is associated with the ISession. Use the returned instance to construct your object graph and then persist any changes.
There are other ways using ISession.Update() with select-before-update in the class mapping or ISession.Lock(obj, LockMode.None).
HTH,
James
--
James Kovacs, B.Sc., M.Sc., MCSD, MCT
Microsoft MVP - C# Architecture
http://www.jameskovacs.comjko...@post.harvard.edu403-397-3177 (mobile)