Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate updates unchanged records

Tags:

nhibernate

When I update (with a flush) one record in a list of records retrieved from the database nHibernate is versioning all of the records that were in the original list.

Retrieving a list of records from the database:

using(UnitOfWork.Start())
{
   queuedJobs = aJobServiceManager.GetAllJobs().Where(aJob => aJob.Status == PricingStatus.QUEUED).ToList();
}

/* Do some work on the record*/
using(UnitOfWork.Start())
{
   //aJob is a record from queuedJobs.
   aJobServiceManager.Save(aJob);
   //When Flush is called I'm expecting only aJob to be updated in the database.
   //aJob is correctly updated BUT
   //All the other records in queuedJobs are also updated (their version field is incremented).
   UnitOfWork.Current.Flush();
}

Why is nHibernate updating all the records when they haven't changed and how do you stop this behavior?

like image 745
brainimus Avatar asked Jul 14 '10 14:07

brainimus


1 Answers

This is most likely the problem you're running into: http://nhibernate.info/blog/2008/10/20/how-test-your-mappings-the-ghostbuster.html

It would help to see your mapping file for job. If you're doing something like

<property name="Status" type="int" /> 

Where Status is actually StatusEnum you'll end up with ghosting.

like image 199
Shane Courtrille Avatar answered Nov 07 '22 02:11

Shane Courtrille