-->
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.  [ 8 posts ] 
Author Message
 Post subject: Why Long living Sessions in Winforms is bad ?
PostPosted: Mon Dec 05, 2005 3:58 pm 
Why Long living Sessions in Winforms is bad ?
Can anyone explain ?
I read numerous posts regarding sessins in winforms.
They all explain how to make sessions short.
But short sessions have major porblem with lazy loaded collections.
They do not handle them. And you end up writing your own custom code for handling lazy loading.

So my question is, why to go over such a pain, and trash what NHibernate session gives you ?
What is the problem of having long sessions in WinForms ?
Stale data ? But short sessions do not solve that problem.
It does not matter if your session is open or not. If user spends 15 minutes to enter data, you have same probablity for stale data with open or closed session.

So any thouths on why long sessions are bad ?


Top
  
 
 Post subject:
PostPosted: Tue Dec 06, 2005 7:41 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
NHibernate session is designed for short conversations: It is not exception proof, there is an DbConnection opened (== valuable resource), it caches all loaded entities, ...

Most of these issues can be "work-around", but it is definitevily simpler and clearer to use short-living sessions.

Note that there are certainly good situations where long living sessions can be used; but if it is only for LazyLoading, it is probably better to find a way to handle that...

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 8:30 am 
I'm having the same problem here.
When using short-lived sessions, or disconnecting them after an action, I get into trouble with lazy-loading.

So I chose to use 1 session in my winApp. But now I run into another problem:

I get an object (e.g. an Employee), I change it (but not yet saving it)
I get a List of those employees.

Seems my changed object has been saved to the database, before the list is being fetched. I don't want that: maybe the user was not going to save the object.


Top
  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 10:26 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
The session can do a transparent persistence when you run a query (to avoid returning stale data...)

In your case, you can either evict your employee or use another session for you second query.

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 8:34 am 
KPixel,

I did, but when I save the Employee, I get following execption:
"a different object with the same identifier value was already associated with the session: 4, of class: Deloitte.UCC.Emerald.BL.Employee".

I stepped through the code to verify if the evict happens, and it does.

Can this be because I get my employee out of an Nhibernate generated IList (sessio.createcriteria(blahblah).List()) ? I do an evict of the employee-object, but maybe the session is still connected to the Employee in the List ?


Top
  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 8:12 pm 
Beginner
Beginner

Joined: Mon Aug 15, 2005 11:09 pm
Posts: 23
Make sure that you're not lazy loading or fetching the Employee again after you evict them.

This is another reason to disconnect the session early. To avoid issues with changing data you don't want to.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 10:33 pm 
I have mentioned a work-around for this kind of problem. Refer to the post:
http://nhibernate.sourceforge.net/forum/viewtopic.php?t=1575 by heyvenki. I have, briefly, described in detail the solution...:)


Top
  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 10:37 pm 
Newbie

Joined: Wed Dec 07, 2005 12:32 am
Posts: 11
Location: Chennai, India
Sorry for posting this as a guest. Should have posted it as heyvenki... :oops:

_________________
Thanks & Regards,
~Venki


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.