Hi Diego, this did work for me. Thank you a lot. Regards
eigeneachse On Nov 24, 12:53 pm, Diego Mijelshon <[email protected]> wrote: > Your mapping is correct. > You have to explicitly set the in-memory object relationships in both > directions. > > The usual way to do this is add a method to ClassA: > > public void AddB(ClassB b) > { > MyList.Add(b); > b.referenceToParent = this; > > } > > If you are directly assigning a List<ClassB> to MyList, then override the > setter to iterate over the list and assign referenceToParent on each B. > > In either case, calling session.Save(classAinstance) should correctly > insert/update A first and all the B's later. > > Diego > > On Tue, Nov 24, 2009 at 08:23, eigeneachse <[email protected]>wrote: > > > h...@all, > > i have the following configuration. > > > ClassA{ > > .... > > IList<ClassB> MyList....... > > ........... > > } > > > ClassB{ > > .... > > ClassA referenceToParent > > .... > > } > > > And my hibernateconfig is as follows. > > ClassA > > <bag name="ClassB" lazy="true" cascade="all" inverse="true"> > > <cache region="10Minutes" usage="read-write" /> > > <key column="CLASSA_ID" /> > > <one-to-many class="ClassB, InMyProject" /> > > </bag> > > > and in ClassB > > <many-to-one name="ClassA" class="ClassA, InMyProject" > > column="CLASSA_ID" /> > > > ( i hope these few informations are enough for you) > > > So now my problem. > > I create a new ClassA object and bind a list of new ClassB objects to > > ClassA. When i save and flush the session, then nhibernate saves all > > my ClassB objects to my db, but WITHOUT the ParentKey to ClassA. If i > > configure the one-to-many relation to inverse=false, then nhibernate > > first inserts into the classB-Table and then updates the reference to > > ClassA. But when i want to allow this, then its necessary to have the > > foreign key in classb to ClassA nullable. But i dont want this. > > > Is there a solution how to tell hibernate to set the parent id in the > > first insert statement without having an update statement afterwards? > > > I hope you can help me. > > Thanks in advance > > > Regards > > > eigeneachse > > > -- > > > 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]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
