-->
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.  [ 2 posts ] 
Author Message
 Post subject: Long session drawbacks?
PostPosted: Wed Jul 26, 2006 10:47 am 
Newbie

Joined: Mon Jul 24, 2006 3:21 pm
Posts: 14
What are the drawbacks to leaving a Hibernate Session open for a really long time? I'm working on a DB-backed DESKTOP app (using Java SE 5, not a web app, not Java EE) that constantly needs to gather more info from the DB as the user decides to look at various screens, etc.

The biggest place where this occurs is in a tree-like viewer. When the user expands nodes, the DB is queried for the child nodes. I would like to be able to simply start one Session for the tree viewer and leave it open until the tree viewer screen is closed.

Does this sound reasonable to anyone?
What's wrong, if anything, with this plan?


Top
 Profile  
 
 Post subject: Re: Long session drawbacks?
PostPosted: Wed Jul 26, 2006 7:15 pm 
Newbie

Joined: Tue Nov 15, 2005 8:27 pm
Posts: 19
Location: Columbia, MO USA
What you describe is called the "Session-per-conversation" pattern and is documented in Chapter 11.3.2 of the reference manual.

http://www.hibernate.org/hib_docs/v3/re ... ongsession

The longer you leave it open, the more stale the data you have cached in your session becomes--other users could have modified it. Hibernate checks instance versions when you flush your changes to the database, throwing an exception if concurrent modification is detected. It is up to you the developer to catch and handle this exception in an intelligent way. Common options are the opportunity for the user to merge changes or to restart the business conversation with non-stale data.

Bruce


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