We had an issue with our application the other day in one particular
use case.  The symptom was Created wasn't being persisted.  All of our
DomainEntities have a Created property and we don't ever set it in our
application.  Instead, we use the IPreUpdateEventListener and
IPreInsertEventListener to handle both Created and LastModified.
(We're using basically the same thing as Ayende
http://ayende.com/Blog/archive/2009/04/29/nhibernate-ipreupdateeventlistener-amp-ipreinserteventlistener.aspx.

After some investigation, I noticed something interesting.  When the
record is inserted, Created is most certainly being set.

if (entity.Created == null)
{
    entity.Created = currentDate;
    Set(persister, state, CreatedName, currentDate);
}

However, within the same transaction in this particular use case,
NHibernate immediately turned around and did an update on the newly
created object.  When this happened, the entity we got had the Created
property set.  However, the value for Created in the state object
array we got was null.  (As it was initially on the insert)

Changing the code in our listener to the following:

if (entity.Created == null)
{
    entity.Created = currentDate;
    Set(persister, state, CreatedName, currentDate);
}
else
{
    Set(persister, state, CreatedName, entity.Created);
}

fixed the issue.

I will be happy to provide more details about what's going on
(modifying one of the collections on the entity seems to be causing
the update to happen in this use case) but I thought this might be an
issue on the NHibernate side.  Has anyone else seen this issue before
using the insert / update listeners?

Thanks in advance.

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

Reply via email to