0

I am using NHibernate 2.0.1 and IPreUpdateEventListener,IPreInsertEventListener events for audit logging purposes.

I have a basic entity that has a one to many relation like this.

User------->Books

From an ASP.NET MVC controller method i am adding a book to a user like this.

Book book =new Book("LOTR");
var userBook=user.AddBook(book);

After session flushing OnPreInsert event called once for newly created Book object than OnPreUpdate called for all books objects in user's books collection even they have not changed.So I am updating LastMofiedDate property of all books objects and I dont want to do this. Is this supposed behaviour of NHibernate or am I missing something?

caltuntas
  • 10,747
  • 7
  • 34
  • 39
  • Maybe you have a ghost mapping that is making every book dirty? Common one is a `DateTime` property that should be a nullable `DateTime?`. – dotjoe Apr 30 '10 at 17:28
  • I will try your suggestion. I am waiting for Monday, My laptop has broken :( – caltuntas May 01 '10 at 16:32

1 Answers1

0

Finally I have solved the problem. The problem was about Enum field on my Book object that mapped as DataType Int32 in mapping file. So NHibernate marks every Book object as dirty after initializition. Further information can be found in this answer

Community
  • 1
  • 1
caltuntas
  • 10,747
  • 7
  • 34
  • 39