Hi. And thanks all for the replies.
Yes, I run all operations within transactions. Unfortunately, disabling or removing constraints is not an option for the production environment. The relation is bidirectional, with inverse="true" on the Parent.Children collection My unit tests indicate that I get the ID's immediately on both Child and Parent with both session.Save and session.Persist and that the INSERTs are delayed until flush. What I'd really like is that the insert and update statements that occur at flush time, are combined to a single insert. As described, that is what happens when I delay the Save / Persist until just before flush / commit time. Best Regards ./Daniel On Feb 14, 5:39 pm, Fabio Maulo <[email protected]> wrote: > Remove that "not nullable" in the PARENT_ID column or make the relation > bidirectional with inverse="true". > Then, if you want all ID of children immediately you have to use > session.Persist instead session.Save. > > > > On Mon, Feb 14, 2011 at 11:42 AM, djn <[email protected]> wrote: > > Hi > > > And thanks for the reply. > > > Our database is oracle, and unfortunately our schema requires a > > sequencer for id generation. All entities have the following type of > > declaration in their hbm file: > > > <id name="MyId" column="MY_ID" access="field.camelcase-underscore" > > > <generator class="native"> > > <param name="sequence">"my_table_seq"</param> > > </generator> > > </id> > > > The output is as follows from NHibernate: > > NHibernate: select "PARENT_SEQ".nextval from dual > > NHibernate: select "CHILD_SEQ".nextval from dual > > NHibernate: INSERT INTO "PARENT" <snip> > > NHibernate: INSERT INTO "CHILD" <snip> > > > And then an exception: > > ORA-01400: kan ikke indsætte NULL i ("SCHEMA"."CHILD"."PARENT_ID") > > If I disable the NOT_NULL constraint, the two inserts are followed by > > UPDATE statements setting the values correctly. > > > As far as I can see, the sequencer select happens immediately and the > > INSERT/UPDATE happens at Flush() / Commit() time. > > > Best regards, > > ./Daniel > > > On Feb 14, 3:24 pm, Oskar Berggren <[email protected]> wrote: > > > Save() does not necessarily issue and immediate INSERT. This depends > > > on your choosen identity generator. > > > >http://ayende.com/Blog/archive/2009/03/20/nhibernate-avoid-identity-g... > > > > /Oskar > > > > 2011/2/14 djn <[email protected]>: > > > > > Hi. > > > > > We're migrating a legacy project from a proprietary in-house ORM to > > > > NHibernate 3.0.0 on .net 4, and it is working fine. > > > > > However, I have a question regarding when to call Session.Save(), when > > > > we create new instances. > > > > > pseudo code: (1) > > > > var p = new Parent(); > > > > var c = new Child(); > > > > _session.Save(p); > > > > _session.Save(c); > > > > c.Parent = p; > > > > p.Children.Add(c); > > > > _session.Flush(); > > > > > If we do the above, nhibernate translates it to two statements, an > > > > INSERT and UPDATE. > > > > But, the Child has not-null constraint on its foreign key so INSERT > > > > fails. > > > > > It works If we do: (2) > > > > var p = new Parent(); > > > > var c = new Child(); > > > > p.Children.Add(c); > > > > c.Parent = p; > > > > _session.Save(p); > > > > _session.Save(c); > > > > _session.Flush(); > > > > > The above samples are simplified, but illustrates our issue quite > > > > well. > > > > > We'd like to do the (1), as that would require the least changes in > > > > our code. Is it possible to tell NHibernate to only make one INSERT > > > > instead of INSERT & UPDATE in that case? > > > > > Best regards, > > > > ./Daniel > > > > > -- > > > > 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 athttp:// > > 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. > > -- > 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.
