-->
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.  [ 5 posts ] 
Author Message
 Post subject: only one session for entire application
PostPosted: Fri Sep 26, 2008 4:52 am 
Newbie

Joined: Fri Sep 26, 2008 4:36 am
Posts: 2
Hi all,

I have been struggling with lazy loading exceptions.

I am developing desktop application, so open session in view filter is not applicable to me.


I thought that, i can open the session at the start of the program and close when the program ends. Every save/update is flushed-commited. Every query result objects are refreshed by calling refresh() on every individual object.

Transaction is independent of session lifetime.

The program is multi-user application with no app. server. A client-db application.


What problems do you think i can encounter with this design?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 26, 2008 7:05 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Bear in mind that a session, object, for as long as it exists, will hold a database connection.

Moreover, if the application is multiuser, the unflushed sessions of 2 different users will continue to grow, likely holding different data. Even if you flush often, your session will differ, unless you were constantly merging everything all the time.

In my opinion, you should painfully work with events (buttons pushed, windows activated, windows closed, lists clicked) and quickly open/close new, short sessions as needed.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 27, 2008 5:21 am 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
The problems you will get:
- a big memory leak: The session keeps every entity in a big map after it touches it once. So after some time you will have the complete database in memory (assuming you have that much memory)
- stale data problems: By default the session keeps the original state of an entity. If you want to see the current state (changed by a different instance of your app for example) you'll have to refresh manually ... and I personally hate everything with 'manually' in it, because it is error prone
- inconsistent data: Now if you refresh part of your objects, you might work with some objects from the beginning of the day, and other from just now ... not a nice situation

The single session aproach works if your application gets restartet often and doesn't use to much data in a single run.

I'd recommend using one session per Dialog/Frame, except for modal Dialogs which use the session of their parent Dialog/frame. Use a Director pattern to control the Frames and their respective Sessions. I wrote a blog article about Hibernate in 2-tier applications (it's german, but maybe it is of some help anyway)[/url]

_________________
Please rate useful posts.


Schauderhaft: Softwaredevelopment, Projectmanagement, Qualitymanagement and all things "schauderhaft"


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 29, 2008 6:26 am 
Newbie

Joined: Fri Sep 26, 2008 4:36 am
Posts: 2
thank you very much


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 29, 2008 7:19 am 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
I actually just created a english version of that article:

http://blog.schauderhaft.de/2008/09/28/ ... lications/

_________________
Please rate useful posts.


Schauderhaft: Softwaredevelopment, Projectmanagement, Qualitymanagement and all things "schauderhaft"


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