I believe sessions are not being kept open per conversation

7 views
Skip to first unread message

Josh Rogers

unread,
Jun 30, 2009, 3:48:57 PM6/30/09
to uNhAddIns
I am using the uNHaddins for session management.  I am using CpBT.

I am having a problem updating a particular object, I am getting this exception:

{System.NullReferenceException: Object reference not set to an instance of an object.
   at uNhAddIns.Adapters.Common.AbstractConversationInterceptor.DisposeConversationOnException() in c:\Documents and Settings\HP_Administrator\Desktop\uNHAddins\uNhAddIns\uNhAddIns.Adapters.Common\AbstractConversationInterceptor.cs:line 156
   at uNhAddIns.CastleAdapters.AutomaticConversationManagement.ConversationInterceptor.Intercept(IInvocation invocation) in c:\Documents and Settings\HP_Administrator\Desktop\uNHAddins\uNhAddIns\uNhAddIns.CastleAdapters\AutomaticConversationManagement\ConversationInterceptor.cs:line 46
   at Castle.DynamicProxy.AbstractInvocation.Proceed()
   at IJobDalProxy7a278f5963de48f4b61264dac839388e.Update(Job job)
   at TEAMSLogic.Impl.JobLogic.Modify(Job job) in C:\Source\TEAMS\TEAMS\TEAMSLogic\Impl\JobLogic.cs:line 316
   at TEAMS.Manager_Forms.frmJobManager.btnSave_Click(Object sender, EventArgs e) in C:\Source\TEAMS\TEAMS\TEAMS\Manager_Forms\frmJobManager.cs:line 399}

This is how I have my DAL setup with the attributes:

namespace TEAMSData.Impl.DALs
{
    [PersistenceConversational]
    public class JobDal: IJobDal
    {
        private readonly IJobDao _JobDao;

        public JobDal(IDaoFactory daoFactory)
        {
            _JobDao = daoFactory.Get<IJobDao>();
        }

        #region IJobDal Members

        [PersistenceConversation]
        public Job GetById(int id)
        {
            return _JobDao.Get(id);
        }

        [PersistenceConversation]
        public Job Save(Job job)
        {
            job.DateAdded = DateTime.Now;
            return _JobDao.Save(job);
        }

        [PersistenceConversation]
        public void Update(Job job)
        {

            if (null == job)
                throw new ArgumentNullException("job");

            job.DateEdited = DateTime.Now;
            _JobDao.Update(job);
        }

        [PersistenceConversation(ConversationEndMode = EndMode.End)]
        public void AcceptAll() { }

        [PersistenceConversation(ConversationEndMode = EndMode.Abort)]
        public void Abort() { } 

        #endregion
    }
}

So what happens is that if I call the Update method, the first time it gives me the above exception, the second time it works just fine.  Which leads me to believe that there is a session that it is trying to acquire but it is not there.  Is there something I am doing wrong here?

Thanks,
Josh


Gustavo Ringel

unread,
Jun 30, 2009, 4:08:31 PM6/30/09
to unha...@googlegroups.com
If Job was already associated to the session and you do update again it will fail. You can use Merge for this.

But I think you may want to review what you are doing, and review the meaning of Update and Get.

If you did a Get and change DateEdited, you don't need an update to get it flushed. the update will try to put in the session an entity that it was already in the session (because of the Get) and then it will fail.

My opinion, remove at all the Update from there, or if you feel your life depend on this Update thing, replace it for a Merge or Refresh, after you check what Merge and Refresh do, to be sure which one you need.

Gustavo.

Josh Rogers

unread,
Jun 30, 2009, 4:22:36 PM6/30/09
to unha...@googlegroups.com
Well now I am completely confused....essentially I have a Job (Object) that contains a list of JobDetails...and I am trying to add a new job detail then save.  How do I do this without calling Update and causing a flush to happen.

I am sorry for my ignorance, but this just is not making sense.

Thanks,
Josh

Gustavo Ringel

unread,
Jun 30, 2009, 4:39:39 PM6/30/09
to unha...@googlegroups.com
you did get, the Job is attached to the session. 
The meaning of Update is attaching to the session, so after get Update is meaningless.
You have the object attached to the session with get, and changes on it will be saved when flushing.
I suggest you to take a look to NH in Action...or Java books for NH, there you have a would explanation of the different functions.

Everyone has its duh moment when understanding what Get/Save/Update mean. 

Do not think Save = INSERT, Update =  UPDATE because it is far far away from this.

Gustavo.

Josh Rogers

unread,
Jun 30, 2009, 4:42:39 PM6/30/09
to unha...@googlegroups.com
Ok....I think after re-reading your statement it makes a bit more sense.  So, if I am understanding correctly, I should only have to call the AcceptAll() after making any changes to the object I have gotten through Get?  I tried this and I got the same exact exception.  So there still must be a piece I am missing.

Thanks,
Josh

Josh Rogers

unread,
Jun 30, 2009, 5:57:29 PM6/30/09
to unha...@googlegroups.com
Ok, I have narrowed it down a little bit.  Job is an Object of type Job, it has a collection of Objects of type JobDetail.  I can make changes to the properties of Job itself and just using AcceptAll it flushes and ends the session as it should.  However once I add a JobDetail to the list then it gives me the above exception.

I am looking at the objects before AcceptAll is called and everything that should be assigned is, nothing is null that shouldn't be null, etc..  The exception doesn't give me any clue whatsoever as to what is failing.

I am at my wits end, please help.
Josh

Gustavo Ringel

unread,
Jul 1, 2009, 4:36:28 AM7/1/09
to unha...@googlegroups.com
I think it is more an NH problem you are having than an uNHAddins problem.
Try to isolate the same flow without using PersistenceConversation, and check where are you failing.
Then you can ask in NHUsers list.

Gustavo.
Reply all
Reply to author
Forward
0 new messages