private static void DeleteOrphans(System.Type entityName, IPersistentCollection pc, ISessionImplementor session) { ICollection orphans; if (pc.WasInitialized) // can't be any orphans if it was not initialized { CollectionEntry ce = session.GetCollectionEntry(pc); orphans = ce == null ? CollectionHelper.EmptyCollection : ce.GetOrphans(entityName, pc); } else { orphans = CollectionHelper.EmptyCollection; } foreach (object orphan in orphans) { if (orphan != null) { session.Delete(orphan); } } }
/// <summary> /// Associate the collection with the given session. /// </summary> /// <param name="session"></param> /// <returns>false if the collection was already associated with the session</returns> public bool SetCurrentSession(ISessionImplementor session) { if (session == this.session // NH: added to fix NH-704 && session.GetCollectionEntry(this) != null ) { return false; } else { if (IsConnectedToSession) { throw new HibernateException("Illegal attempt to associate a collection with two open sessions"); } else { this.session = session; return true; } } }