-->
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: Stale Sessions in Hibernate
PostPosted: Wed Oct 20, 2010 12:13 pm 
Newbie

Joined: Wed Oct 20, 2010 12:06 pm
Posts: 3
Hi Friends,

I'm developing a web application in Java where i use Hibernate with PostgreSQL.

Things are going good, but i have a concern with my approach. I'm not sure if I'm doing the right thing.

When a user logs in, I create a httpSession and hibernateSession. I store the hibernateSession as an attribute in the httpSession.

I'm not sure if it is a good practice as i've seen in a couple of forums that the hibernateSession becomes stale if we keep it open for too long. But since creating a new HibernateSession each time hits the performance, i don't want to keep creating and closing it every time.

Please suggest me what i can do.


Top
 Profile  
 
 Post subject: Re: Stale Sessions in Hibernate
PostPosted: Wed Oct 20, 2010 1:52 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
I'm not sure if it is a good practice as i've seen in a couple of forums that the hibernateSession becomes stale if we keep it open for too long. But since creating a new HibernateSession each time hits the performance, i don't want to keep creating and closing it every time.


It doesn't hit performance to create a new session for every request. Keeping it in the httpSession is likely to cause trouble and performance issues sooner or later. Eg. first-level cache using up a lot of memory, thread/synchronization issues, automatic-dirty checking taking a long time, etc.

Here is a quote from the documentation at http://docs.jboss.org/hibernate/stable/ ... ons-basics

Quote:
A Session is an inexpensive, non-threadsafe object that should be used once and then discarded for: a single request, a conversation or a single unit of work.


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.