-->
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: Best practice for disconnected applications (WinForms)
PostPosted: Tue Sep 20, 2005 3:19 am 
Beginner
Beginner

Joined: Fri May 20, 2005 5:06 am
Posts: 28
As I wrote in a different posting, I had a problem that Session.Flush took 11 sec, just to save one object, because I had 11.000 objects in memory. All my attempts to speed that up failed. I see the following possibilities (and their problems) for my problem:

1.) One big session for the app. Everytime I need data, I reconnect and get them from DB, everytime I save data, I reconnect and save to DB. That's what I do now, with the problem, that with many objects it is very slow at flushing.

2.) One big session to get all data, and a second small one, which I always clear and associate only the objects I want to save before updating just the data I want to save. PROBLEM: I get the following exception: "Illegal attempt to associate a collection with two open sessions"

3.) One session, which I always clear before saving and just associate with Lock the object(s) I want to save. There I have two problems: PROBLEM 1: When trying to associate I get the exception: reassociated object has dirty collection reference. And PROBLEM 2: After I clearing the session, it can happen that (because of a reference) a object is reloaded from the DB, which I already loaded, as a seperate object in memory (because the first one is not longer in the session). So I have two identical representations of the same object.

I hope you understand my problem. the question is, what is the best practice to solve my problem, which is a standard usage scenario for NHibernate.

Thanks alot, Rainer.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 9:34 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Have you read: How to handle session in winforms?

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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 1:57 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You should never use one big session for the entire application. Sessions should be small and relatively short-lived and correspond to some kind of transaction, so that you can rollback and throw away the whole session in case something goes wrong.

Regarding your option 3), can you just start a new session and call session.SaveOrUpdate(myNewOrChangedObject)?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 23, 2005 9:33 am 
Beginner
Beginner

Joined: Fri May 20, 2005 5:06 am
Posts: 28
Thanks for the link to the other thread. I will write there.


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.