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.