-->
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.  [ 3 posts ] 
Author Message
 Post subject: Advice for Session creation/closing in servlets
PostPosted: Thu Apr 21, 2005 6:54 pm 
Newbie

Joined: Thu Apr 21, 2005 6:27 pm
Posts: 1
Location: Crookston, MN, US
Hibernate version: 2.1.6

Name and version of the database you are using: MySQL 4.1 w/InnoDB

Hello all,

I am rather new to the JBoss/Hibernate scene and have a question regarding the creation and closing of Sessions.

I have been trying to figure out how the Servlet lifecycle and reuse will affect the persistance behavior if I open a Session in a servlet's init() and close it on destroy(). Presently I open and close the session in the doWhatever() method.

Is it approprate to leave a session open for a servlet's entire lifecycle? And, will there be any impact on transactions by leaving a session open through what may be different queries made by different users? Finally, will this even cause a more than negligable performance increase?

I have been trying to figure this out but figured I would ask around before I did any major code changes, since I do not feel I have an adaquate grasp of everything yet to do so.

Thanks in advance!
mod_critical

P.S.
Recently switched away from Sun Java System Application Server and using CMP entity beans... ... ...
Thank you Hibernate team for making persistance more like a lullaby and less like getting stabbed in the face.


Top
 Profile  
 
 Post subject: Did you find your answers?
PostPosted: Wed Apr 27, 2005 11:04 am 
Beginner
Beginner

Joined: Mon Apr 18, 2005 10:25 am
Posts: 38
Location: Maryland
I have the same questions as you about leaving a session open. Did you get an answer? Can you post or email me a sample?

jacky@itmc-wo.com
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 27, 2005 2:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Absolutely not. A Session should not be accessed concurrently. Also a Session represents a transactional cache of data; keeping one around and re-using it can lead to staleness issues.

The typical usage pattern for servlet containers is to apply servlet filters, and open a session to handle each incoming request.


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