All,
When loading an entity and its association path eagerly, then calling session.Flush(), causes an Update() to run on the associated entity.
Ex:
Invoice -> Project
Loading single invoice and the associated Project (loading Project eagerly), then calling session.Flush() runs an Update() statement on the Project. NO CHANGES have been done at all between the load and the Flush to any of the entities.
IStatefulSession sess = PersistentInvoiceHeader.AcquireCurrentSession();
InvoiceHeader hdr = sess.Session.CreateCriteria<InvoiceHeader>()
.Add(Restrictions.Eq(InvoiceHeader.PROP_ENTITYID, 25051))
.SetFetchMode(InvoiceHeader.PROP_PROJECT, NHibernate.FetchMode.Eager)
.UniqueResult<InvoiceHeader>();
sess.Session.Flush();
Trace (Job_Info is the Project entity associated w/ the invoice):
NHibernate: SELECT ... FROM InvoiceHeader this_ inner join Job_Info project2_ on this_.ProjectId=project2_.entity_id WHERE this_.entity_id = @p0;@p0 = 25051 [Type: Int32 (0)]
NHibernate: UPDATE Job_Info SET RowVersion = @p0, Created = @p1, LastUpdated = @p2, public_surveyor = @p3, guid = @p4, updated_at = @p5, status = @p6, entry_date = @p7, file_number = @p8, client_reference = @p9, contact = @p10, order_date = @p11, instructions_1 = @p12, instructions_2 = @p13, instructions_3 = @p14, instrument = @p15, quote = @p16, quote_document = @p17, pin = @p18, project_notes = @p19, due_date = @p20, due_date_fw = @p21, lock_status = @p22, plan_attached = @p23, notes_attached = @p24, type_extra = @p25, currency_code = @p26, master_job_id = @p27, manager_id = @p28, contact_id = @p29, office_id = @p30, job_type_id = @p31, client_entity_id = @p32, country_id = @p33, region_id = @p34 WHERE entity_id = @p35 AND RowVersion = @p36;
I am really surprised that Nhibernate is running an Update() statement on something that has not changed! None of the entities are dirty, why would there be an Update?
I am using Nhibernate 3.3, .net 4.0, this is Console app.