If you use assigned-identifier, and mix 'old'+'new' (i.e., persistent+transient) objects, NH cannot determine what has to be inserted and what is already there just by looking at the IDs.
You should load the existing persisted entities first. var referenceEntity = session.Load<ReferenceType>(idThatIKnowExistsInTheDb); The best solution is to not use assigned identifiers. On 19 March 2012 21:26, guilemsola <[email protected]> wrote: > Hi all, > > I have discovered that with nhibernate profiler with entities created > for the very first time... > > In my application I create a new entity that has a list of steps, and > each step a list of values. (I'm using inverses on mappings). Also > entities and steps references to master values already in db. So there > is a kind of mix of old and new objects. > > When I do the first Save I do Session.Save(entity) and the whole tree > is saved in database as it should be, but NH profiler warns about > that: > > Unable to determine if StepValueEntity with assigned identifier > ede6a5ee-b4bd-4f67-9c64-11ef85b7d6ff is transient or detached; > querying the database. Use explicit Save() or Update() in session to > prevent this. > > And effectively prior all the new entities insert there are a lot of > useless selects from NH because entities are not on DB. > > This is very inefficient, so what is the correct way to store those > new entities and tell NH that they are new? > > > > FYI this is how I do mapping for identity columns, maybe this doesn't > give a clue to nhibernate to know about what are new and already > persisted entities and I should do it in another way. > > Id(x => > x.Id).Column("GUID_PIPELINE_STEP_PARAMETER").GeneratedBy.Assigned(); > > Thanks in advance > > -- > 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. > > -- 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.
