I had a problem, examined the NHibernate 3.1 source, and think I've found a bug.
If 'collection' is an NHibernate Lazy=true, Inverse=true bidirectional one-to-many collection, then this works: var child = new Child(); NHibernateUtil.Initialize(collection); child.Parent = p; p.collection.Add(child); child.Parent = null; p.collection.Remove(child); ... but this fails with TransientObjectException: var child = new Child(); // NHibernateUtil.Initialize(collection); child.Parent = p; p.collection.Add(child); child.Parent = null; p.collection.Remove(child); It seems that the 'snapshot' used by NHibernate's AbstractPersistenceCollection.GetOrphans() method is not set quite correctly when items are added to a not-yet initialized collection (IsOperationQueueEnabled == true), then when the collection is initialized (a call to AbstractPersistenceCollection.Write()), the snapshot includes the already queued added items (when presumably it should not). Flush calls Cascade.DeleteOrphans(), which thinks the transient child above is in the pre-session state snapshot, and tries to delete it, but can't and raises TransientObjectException. I don't have time at the moment to create a unit test. -- 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.
