protected override object ProcessCollection(object collection, PersistentCollectionType type) { ICollectionPersister persister = Session.GetCollectionPersister(type.Role); if (collection == null) { // Do nothing } else if (collection is PersistentCollection) { PersistentCollection coll = (PersistentCollection)collection; if (coll.SetCurrentSession(Session)) { ICollectionSnapshot snapshot = coll.CollectionSnapshot; if (SessionImpl.IsOwnerUnchanged(snapshot, persister, this.Key)) { // a "detached" collection that originally belonged to the same entity if (snapshot.Dirty) { throw new HibernateException("reassociated object has dirty collection"); } Session.ReattachCollection(coll, snapshot); } else { // a "detached" collection that belonged to a different entity throw new HibernateException("reassociated object has dirty collection reference"); } } else { // a collection loaded in the current session // can not possibly be the collection belonging // to the entity passed to update() throw new HibernateException("reassociated object has dirty collection reference"); } } else { // brand new collection //TODO: or an array!! we can't lock objects with arrays now?? throw new HibernateException("reassociated object has dirty collection reference"); } return(null); }
protected override object ProcessCollection(object collection, PersistentCollectionType type) { ICollectionPersister persister = Session.GetCollectionPersister(type.Role); if (collection is PersistentCollection) { PersistentCollection wrapper = (PersistentCollection)collection; if (wrapper.SetCurrentSession(Session)) { //a "detached" collection! ICollectionSnapshot snapshot = wrapper.CollectionSnapshot; if (!SessionImpl.IsOwnerUnchanged(snapshot, persister, Key)) { // if the collection belonged to a different entity, // clean up the existing state of the collection Session.RemoveCollection(persister, Key); } Session.ReattachCollection(wrapper, snapshot); } else { // a collection loaded in the current session // can not possibly be the collection belonging // to the entity passed to update() Session.RemoveCollection(persister, Key); } } else { // null or brand new collection // this will also (inefficiently) handle arrays, which have // no snapshot, so we can't do any better Session.RemoveCollection(persister, Key); //processArrayOrNewCollection(collection, type); } return(null); }