another example of no consistent domain in memory : var p = session.Get<Person>(1); var a = p.Addresses[0]; p.Addresses.Remove(a); At this point the Address instance "a" was dissociated from Person1 but... a.Person.Should().Be.Null(); <== will fail
Similar examples can be write for reparenting and any other bidirectional association including bidirectional-many-to-many. Probably we will include this matter in the new book about NH3 (Jason is cooking it). On Mon, Jun 7, 2010 at 11:31 AM, Fabio Maulo <[email protected]> wrote: > your domain must be consistent in memory. > When it is consistent in memory you can be pretty sure that NH will persist > it as expected. > > An example of no consistent domain: > var p = session.Get<Person>(1); > var a = new Address(); > a.Person = p; > At this point you have an Address for the Person1 but... > p.Addresses.Should().Contains(a); <== will fail > > > On Mon, Jun 7, 2010 at 7:05 AM, Ahmed Emad <[email protected]> wrote: > >> thanks for your speed reply and attention >> >> but sorry , i couldn't understand it well >> >> does that mean that the two links are seprated and i need to manage it by >> myself? >> >> >> On 7 June 2010 12:37, Oskar Berggren <[email protected]> wrote: >> >>> This is according to spec: >>> http://nhforge.org/doc/nh/en/index.html#collections-bidirectional >>> >>> Also discussed on this list a few days ago: >>> >>> http://groups.google.com/group/nhusers/browse_thread/thread/d9e7735a80171108 >>> >>> /Oskar >>> >>> >>> 2010/6/7 Ahmed Emad <[email protected]>: >>> > Hi , >>> > i have 2 entities : ( person ) & (Address) >>> > >>> > with follwing mapping : >>> > >>> > - <class name="Adress" table="Adress" lazy="false"> >>> > - <id name="Id" column="Id"> >>> > <generator class="native" /> >>> > </id> >>> > - <many-to-one name="Person" class="Person"> >>> > <column name="PersonId" /> >>> > </many-to-one> >>> > </class> >>> > >>> > >>> > ----------------------------------------------------------- >>> > >>> > - <class name="Person" table="Person" lazy="false"> >>> > - <id name="PersonId" column="PersonId"> >>> > <generator class="native" /> >>> > </id> >>> > <property name="Name" column="Name" type="String" not-null="true" / >>> >> >>> > - <set name="Adresses" lazy="true" inverse="true" cascade="save- >>> > update"> >>> > - <key> >>> > <column name="PersonId" /> >>> > </key> >>> > <one-to-many class="Adress" /> >>> > </set> >>> > >>> > ----- >>> > my propblem is that when i set Adrees.Person with new object of >>> > person ,The collection person.Adresses doesn't update itself . >>> > >>> > should i update every end role of the association to be updated in the >>> > two both? >>> > >>> > another thing : if i updated the Fk manually like this : >>> > Adress.PersonId it doesn't break or change association. does this is >>> > Nhibernte behavior ? >>> > >>> > thanks in advance , i am waiting for your experiencies >>> > >>> > -- >>> > 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]<nhusers%[email protected]> >>> . >>> > For more options, visit this group at >>> http://groups.google.com/group/nhusers?hl=en. >>> > >>> > >>> >>> -- >>> 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]<nhusers%[email protected]> >>> . >>> For more options, visit this group at >>> http://groups.google.com/group/nhusers?hl=en. >>> >>> >> -- >> 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]<nhusers%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/nhusers?hl=en. >> > > > > -- > Fabio Maulo > > -- Fabio Maulo -- 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.
