Nhibernate profiler shows warning "Use explicit save or update in session"

I have a problem persisting in session objects created the first time ...

Each object has a list of steps, and each step has a list of values. (I use inversions for comparisons). In addition, entities and stages refer to the main values ​​already in the db. Thus, there is a variety of old and new objects.

When I do the first Save, I do Session.Save(entity)

and the whole tree is saved to the database.

The problem stems from the profiler warning messages like

Unable to determine if the StepValueEntity with the assigned ID ede6a5ee-b4bd-4f67-9c64-11ef85b7d6ff is temporary or disconnected; database query. Use the Save () or Update () checkbox in the session to prevent this.

because nhibernate makes a lot of updates before actually starting to embed things.

What am I doing wrong?

I've tried something like repeating each step and the meaning and explication keep it, but the same thing happens.

Edit:

This is how I do the mapping for the identity columns, maybe it doesn't give nhibernate a hint to know about new and already persisted objects and I have to do it differently.

Id(x => x.Id).Column("GUID_PIPELINE_STEP_PARAMETER").GeneratedBy.Assigned();

      

Hello

+3


source to share


2 answers


You might have forgotten about the transaction, take a look: http://nhprof.com/Learn/Alerts/DoNotUseImplicitTransactions



using (var session = sessionFactory.OpenSesion())
using (var tx = session.BeginTransaction())
{
    // perform your insert here
    tx.Commit();
}

      

+2


source


For the record, I made the same question to the nhusers group and some people came up with ideas on how to focus on this topic.

http://groups.google.com/group/nhusers/browse_thread/thread/bcc962d861c7f111



The most recommended option, and the one I choose, was to not use the auto-generated id and use one generator when matching. This way, NH easily knows that an object with an empty id has never been inserted.

I choose the Guid comb generator which creates a unique GUID that solves the fragmented index problem

0


source







All Articles