Whether or not NHibernate is making changes is irellevant. If an UPDATE
statement is issued, the database is being modified, which is a sign of
aither a) wrong mapping or b) modification during load. From my experience,
the most typical reason for NH to issue UPDATEs to the database is because
of modifications during load, but that's just from my point of view.
Again, if the entities are modified during load, NH thinks they are dirty in
that session, which causes an update (the comparison between the actual
values and the loaded entites doesn't match.)

I believe one can implement GetHashCode() which "should" take care of the
problem, but in general (although recomended), that should not be necessary.

2009/6/29 Jason Meckley <jasonmeck...@gmail.com>

>
> if you want to see what NH is doing behind the scenes check out
> www.nhprof.com. cost is dirt cheap, especially for the wealth of
> knowledge it provides.
>
> the updates happen at flush because this is how NH works. up until you
> flush the session NH is simply tracking changes. it's not actually
> making changes (that's not entirely true depending on the PK
> generator).
>
>
>
> On Jun 29, 4:41 pm, Kenneth Siewers Møller <kenneth.siew...@gmail.com>
> wrote:
> > I don't know whether it's the same issue, but I usually experienced this
> > behavior when I (unintentianally) was modifying my entities when loading
> > them from the database. NHibernate thinks they are dirty and therefore
> tries
> > to update the changes when the session is flushed.
> > At that time, I didn't fully understand the flushing behavior of
> NHibernate,
> > so I was very frustrated. In my case, I found that I was using the
> > properties of my entities, which had custom logic for the setters, which
> of
> > course made NHibernate unable to compare the curret values. Changing the
> > access method from the default property to field access, made the problem
> > disapear.
> >
> > Again, I don't know if this apply to your problem, but it might... :)
> >
> > 2009/6/29 Brian Sullivan <bmsulli...@gmail.com>
> >
> >
> >
> > > Oskar,
> >
> > > Thanks for the reply!  Yes, it looks like calling ToList() does cause
> > > the update to happen as well (once I call session.Flush()).  I'm not
> > > sure if anything is actually being updated, since unfortunately SQL
> > > Profiler doesn't provide the values for the "@" params in its
> > > display.  I'd have to check the values in the table.  However, the
> > > fact that an UPDATE is being issued at all is cause for concern.
> >
> > > You mentioned NULLs in varchar columns being a potential problem.  I
> > > know for certain that some of the varchar fields in the Contacts table
> > > are nullable.  How can I verify that this is indeed what's happening
> > > to cause the update, and how can I best address it?
> >
> > > Thanks again for the help!
> >
> > > -Brian
> >
> > > On Jun 29, 1:59 pm, Oskar Berggren <oskar.bergg...@gmail.com> wrote:
> > > > Does the UPDATE statement actually change something? One thing I can
> > > > think of is a NULL in a varchar column somewhere being coerced into
> an
> > > > empty string, which NHibernate then sees as a dirty object. Or the
> > > > other way around. Does this happen even if you comment out the two
> > > > rows involving dlContact, but call ToList() on contacts to force it
> to
> > > > "materialize"?
> >
> > > > /Oskar
> >
> > > > 2009/6/29 Brian Sullivan <bmsulli...@gmail.com>:
> >
> > > > > I'm starting to play with NHibernate to make a case for its use in
> our
> > > > > company's projects. I've created a branch of one of our solutions
> and
> > > > > have started to convert some of the data access to using NHibernate
> as
> > > > > a proof-of-concept. However, while looking at SQL Profiler, I
> > > > > discovered that NHibernate is issuing an update command to the
> > > > > database when I databind an IList that I get back from a Criteria
> > > > > query to a Datalist control. The Criteria query looks like this:
> >
> > > > >  var contacts = session.Get<Location>(LocationId).Contacts
> > > > >                .OrderBy(x => x.LastName)
> > > > >                .ThenBy(x => x.FirstName)
> > > > >                .ThenBy(x => x.ContactType.TypeName)
> > > > >                .ThenBy(x => x.ContactID);
> > > > >  dlContact.DataSource = contacts;
> > > > >  dlContact.DataBind();
> > > > > I'm getting the list of contacts that are associated with a
> particular
> > > > > location in our system. To be clear, the update does not seem to be
> > > > > issued right as DataBind() is called, but when the session is
> flushed
> > > > > at the end of the request. It issues an update to the Contacts
> table,
> > > > > not the Location table. And it's a single update, too, not one
> update
> > > > > for each contact associated with the location.
> >
> > > > > Why does NHibernate think it needs to update the database? Is the
> > > > > databinding changing the value of one of the Contact entities
> returned
> > > > > from the query somehow? I'm just displaying the values on the page,
> > > > > not changing them anywhere that I can tell.
> >
> > > > > Any help would be much appreciated. I can provide more code context
> if
> > > > > it would be helpful.
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to nhusers@googlegroups.com
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to