From: NHibernate J. <mik...@us...> - 2006-11-02 06:59:29
|
[ http://jira.nhibernate.org/browse/NH-552?page=all ] Sergey Koshcheyev closed NH-552: -------------------------------- Resolution: Fixed > Collection of "nullifiables" not updated when object saved back > --------------------------------------------------------------- > > Key: NH-552 > URL: http://jira.nhibernate.org/browse/NH-552 > Project: NHibernate > Type: Bug > Components: Core > Versions: 1.0.2 > Reporter: Alexis Seigneurin > Priority: Trivial > Fix For: 1.0.3, 1.2.0.Alpha1 > > In the SessionImpl class, the collection named "nullifiables" keeps track of objects which have been deleted. If, for a reason or another, we decide to save such an object back in the database, this object is still considered "nullifiable". The impact is that any reference to that object will be set to "null". > In the application we are developping, all the generators are of type "assigned". This is because the objects are loaded from a remote location which is responsible for the generation of the identifiers. Each object can be saved and deleted more than once by NHibernate. It is therefore important to remove an object from the "nullifiables" collection when it is saved back. > Here are two mappings ("Question" and "Answer") : > <class name="Question" table="QUESTION"> > <id name="Id" type="long"> > <generator class="assigned"/> > </id> > <set name="Answers" inverse="true" lazy="true" access="NHibernate.Generics.GenericAccessor, NHibernate.Generics"> > <key column="Question"/> > <one-to-many class="Answer"/> > </set> > </class> > <class name="Answer" table="ANSWER"> > <id name="Id" type="long"> > <generator class="assigned"/> > </id> > <many-to-one name="Question" not-null="true" access="NHibernate.Generics.GenericAccessor, NHibernate.Generics"/> > </class> > Each Answer belongs to a single Question. Each Question contains one or more Answers. > To reproduce the bug, you need to: > - save a Question (with ID=1) (let's say it has no linked Answers, at this point) > - delete the Question (ID=1) > - save the Question once again (ID=1) > - save an Answer linked to the Question => the linked property (Question in the Answer instance) is "nullified" and the not-null constraint gets violated. > Here is a patch: > $ diff -C 5 SessionImpl.orig.cs SessionImpl.cs > *** SessionImpl.orig.cs Mon Feb 27 18:29:02 2006 > --- SessionImpl.cs Mon Feb 27 18:30:01 2006 > *************** > *** 709,718 **** > --- 709,722 ---- > } > } > //id might be generated by SQL insert > object id = SaveWithGeneratedIdentifier( theObj, Cascades.CascadingAction.ActionSaveUpdate, null ); > + > + IClassPersister persister = GetPersister(theObj); > + nullifiables.Remove(new Key(id, persister)); > + > ReassociateProxy( obj, id ); > return id; > } > private void ForceFlush( EntityEntry e ) -- 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 |