-->
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: Keeping session always open
PostPosted: Mon Dec 14, 2009 1:21 pm 
Newbie

Joined: Mon Dec 14, 2009 12:34 pm
Posts: 2
Hello all,
I don't know whether this question is answered or not because I'm unable to find answer for my question. What is the good way to use hibernate. I'm actually talking about session opening and closing. Should we open a session at the start of application and close it when our application closes? OR We should open it every time we need to do some thing with database and then close the session again. What I observed is that opening and closing sessions takes lot of time and application slows down. But if I keep the session open the performance really increases. I dont know any of the risks involved. What would you say about this ?


lets say there are 4 classes A, B, C and a HibernateUtil. A, B and C call method
Code:
HibernateUtil.getInstance().getSession();
and HibernateUtil class returns the session object which is static in hibernate. If it is null it initializes and returns.
now whats are the side effects if i keep the connection open ?

or can some one please provide me a small project made using hibernate so that i can learn the best approach to use hibernate.


Top
 Profile  
 
 Post subject: Re: Keeping session always open
PostPosted: Mon Dec 14, 2009 3:00 pm 
Newbie

Joined: Tue Jun 23, 2009 7:59 am
Posts: 6
Tamour,

The answers to your questions depend on the nature of the application you are developing. There are different approaches for different types of applications.

You always need to study which one is the best for your case as all of them will bring benefits as well as new possible problems. For example the Open Session in View: https://www.hibernate.org/43.html is an approach for web application but has its issues.

Also, there are some frameworks to help you with all the persistence perspective, e.g. Seam and Spring.

Luiz Filipe


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.