-->
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: When to close my session factory?
PostPosted: Mon Oct 06, 2008 6:30 am 
Newbie

Joined: Thu Oct 02, 2008 6:46 am
Posts: 5
I want to use Hibernate in a Swing application. I try to keep sessions open as short as possible, but when should I call close() on my instance of SessionFactory? Right after closing my sessions or at application shutdown?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2008 7:25 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
A SessionFactory is (relatively) expensive to create so you should keep it as long as you have need for it. In other words, you should not close it until your application is shutting down.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2008 8:13 am 
Newbie

Joined: Thu Oct 02, 2008 6:46 am
Posts: 5
Thanks for your reply. From what I observe, building/configuring a SessionFactory is expensive (so I do this only once). Calling sessionFactory.close(), however, does not seem to result in all that work being done again. For example, I can still call openSession() on my closed factory and do not notice a slower response of my GUI. So what does close() actually do?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2008 8:19 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Oh... I have never tried that. I have always assumed that a session factory would be unusable after closing it. Why do you want to close and continue to use it?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2008 8:35 am 
Newbie

Joined: Thu Oct 02, 2008 6:46 am
Posts: 5
From what I read, there are good reasons to close a session when you're done. I just wondered whether the same is true for a sessionFactory. What happens if a user keeps my Swing application open for several hours?


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.