From: NHibernate J. <mik...@us...> - 2006-11-13 18:05:03
|
[ http://jira.nhibernate.org/browse/NH-558?page=all ] Sergey Koshcheyev updated NH-558: --------------------------------- Fix Version: LATER > Collections recreate, whether entity is dirty or not > ----------------------------------------------------- > > Key: NH-558 > URL: http://jira.nhibernate.org/browse/NH-558 > Project: NHibernate > Type: Improvement > Components: Core > Versions: 1.0.2 > Reporter: Ruurd Boeke > Priority: Minor > Fix For: LATER > Attachments: changes.rar > > When an entity that owns a collection is attached to a session by SaveOrUpdate, the owned collection will be scheduled for recreation, whether the entity is dirty or not. > Since a collection should be treated as a field/value on that entity, it should only be recreated/updated when the entity is dirty. > It is my strong believe that the current NH does not give enough hooks to manage these things. They are especially important when objects are detached and the managed persistent collection types are replaced with custom collections (for instance when the communication layer is webservices, instead of remoting). Developers need a powerful attaching story, which allows them to set the state to exactly what they want, if they have chosen to keep all that state. > OnUpdateVisitor was changed by adding this: > ---------------------------------- > bool dirty = Session.Interceptor.IsCollectionDirty(topentity, collection, type.Role); // have had to add this > if (dirty) > Session.RemoveCollection(persister, Key); > else > { > // wrap our collection into the appropriate type > IPersistentCollection wrapper = type.Wrap(Session, collection); > wrapper.SetCurrentSession(Session); > // if the entity is not dirty, then the collection should not recreate itself > // so the loaded state can be set to exactly the same as the current state. Then our dirty mechanisms will skip recreating the collection > CollectionSnapshot snapshot = new CollectionSnapshot(Key, type.Role, (ICollection) collection); > wrapper.CollectionSnapshot = snapshot; > IEntityPersister entityPersistor = Session.GetPersister(topentity); > IType[] types = entityPersistor.PropertyTypes; > int i = 0; > for (i = 0; i < types.Length; i++) > { > if (types[i].Equals(type)) > break; > } > // the new managed collection needs to be set on the property > entityPersistor.SetPropertyValue(topentity, i, wrapper); > // reattach to the session including the snapshot > Session.ReattachCollection(wrapper, snapshot); > } > ---------------------------------- > This will allow for the default behaviour of recreation, but also give a hook to the developer to determine if the collection is dirty or not. > Better would be to add the possibility to specify the loaded state all together, and have the collectionsnapshot be specified by the programmer. > Attached are the files that were changed. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.nhibernate.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |