Hi Team,
We have Nhiberbate.IInterceptor based auditing enabled in our application. NHibernate is integrated within Spring.NET in the implementation. The auditing works fine with Entities within the same session.
1) ie:
Code:
[Transaction]
public virtual void RunAppSettingTesting()
{
ApplicationSetting appSett = ApplicationSettingDataAccess.GetById(3);
appSett.UpdatedBy = "Me @ 14:06";
appSett.Description = "Me @ 13:06";
ApplicationSettingDataAccess.Update(appSett);
}
As you can see the Entity is used within the same Transaction and session of NHibernate (Object creations are handled by Spring). The session is injected to this class by Spring.
2) However, if we do the following in a separate code
Code:
IApplicationSettingDataAccess access = (IApplicationSettingDataAccess)ctx.GetObject("ApplicationSettingDataAccess");
ApplicationSetting appSett = access.GetById(3);
appSett.UpdatedBy = "Me @ 16:06";
appSett.Description = "Me @ 16:06";
access.Update(appSett);
The first line ctx.GetObject will be in a separate session (or think this scenario as get the object to a web interface, edit and then update)
Below is the implementation we got for IInterceptor.OnFlushDirty
Code:
public bool OnFlushDirty(object entity,
object id,
object[] currentState,
object[] previousState,
string[] propertyNames,
IType[] types)
{
if (entity is IAuditable && !(entity is IAuditObject))
{
_log.Debug("AuditInterceptor OnFlushDirty");
// Check the previous state, this will be null if there is an optimistic locking
// exception.
if (previousState == null)
return false;
.........
}
in the later case
if (previousState == null) the previous state is not maintained by
IInterceptor.
The ApplicationSettingHst object was successfully saved by the Interceptor in the first case where and not in the later case. We suspect this is due to the detached objects being not handled in the Interceptor correctly. Could you please help us whether we can implement the auditing of detached entities in Nhibernate or not. Or is there any releases we can use to get this working?
Thanks a lot
Best Regards
Mat
[/code]