These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: NHibernate detached objects
PostPosted: Thu Oct 16, 2008 12:01 pm 
Newbie

Joined: Thu Oct 16, 2008 11:25 am
Posts: 1
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]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.