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.  [ 4 posts ] 
Author Message
 Post subject: WinForms Session Management
PostPosted: Wed Aug 30, 2006 2:03 pm 
Regular
Regular

Joined: Fri Jan 27, 2006 2:32 pm
Posts: 102
Location: California, USA
I have a MDI win forms application in c# that I am writing.

I don't think I have implemented very good session management.

In my application, a user can have more than one page open at a time. (Pages are child winform objects). So on one page, the user could be creating a new Foo object while on another page the user could be updating a Bar object. When the user saves his new Foo object, any edits made to the Bar object are flushed. I don't want changes to the Bar object flushed, though. Each page needs to be savable seperatly.

I know the problem is because I am using one session for all of my application. I can see why this is bad, now.

But my question is, what is the best way to do this? Should each page have its own session? That is my first thought, but before i go down that road, I wanted to get some feedback. Can I even have multiple sessions open at the same time?

Is there a way to have an MDI application or will I really have to change and make the user work on "one thing a a time"

Thanks for any advice or tips...

Brian


Top
 Profile  
 
 Post subject: Bug?
PostPosted: Thu Aug 31, 2006 12:16 pm 
Regular
Regular

Joined: Fri Jan 27, 2006 2:32 pm
Posts: 102
Location: California, USA
I have setup a session manager to issue a new session to each of my MDI child forms.

But when I try to save, I am getting a NullReferenceException.

This exception occurs when I try to commit my transaction after a SaveOrUpdate() call.

The object I am saving has a many-to-one property called LastUpdatedBy that identifies the user who change the object.

When trying to save that property, it throws the exception.

It is thrown from NHibernate.Engine.Cascades.VersionValue.IsUnsaved(object version)

The line that throws the exception:
Code:
  return version == null || value.Equals(version);


This is because "version" = 5, but "value" is null. So the first part returns false but the value.Equals() throws an exception because value is null.

The object I am trying to save is not unsaved. (iow, it was loaded from the database via a QBE query)




Any hints on what might be wrong here?? I am using NHibernate 1.2.0.Alpha1.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 31, 2006 1:57 pm 
Beginner
Beginner

Joined: Mon Mar 06, 2006 2:19 pm
Posts: 42
Location: Belo Horizonte, Brazil
I have the same problem. For now I am ending the session every time I save or delete. I know this isn't a good thing but I will try to make big changes in the future. If you search the forum you will find other people talking about this.


Top
 Profile  
 
 Post subject: Re: Bug?
PostPosted: Thu Aug 31, 2006 5:11 pm 
Regular
Regular

Joined: Fri Jan 27, 2006 2:32 pm
Posts: 102
Location: California, USA
pelton wrote:
But when I try to save, I am getting a NullReferenceException.


I think I found the reason why I was getting this exception. In my mapping file, I had this:

Code:
  <version name="NhVersion" column="nh_version" type="long" />


This has been working fine for quite some time. But in reading some posts on the forum, I thought I would try this:

Code:
  <version name="NhVersion" column="nh_version" type="long" unsaved-value="null" />


That seems to have fixed the problem. I'm able to open a new session for each of my winforms and have each form isolated from each other. (i.e. Save on Form B doesn't try to save changes made to Form A). There might be some kinks to work out, but it seems to be working. No exceptions and data actually makes it to the database!

Still have no idea why it has been working for so long without the "unsaved-value" config setting, but ohhhh well.


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

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.