-->
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.  [ 1 post ] 
Author Message
 Post subject: LESSON LEARNED, - Session managment
PostPosted: Tue Feb 03, 2004 1:52 am 
Newbie

Joined: Fri Dec 05, 2003 12:42 am
Posts: 3
I have hibernate all over several apps (great tool!) and I wanted to use it to grab a connection for a single admin type servlet to look at metadata on a DB during development. So I wrote a line like this...

Code:
            Connection connection = HibernateFactory.getInstance().getFactory().openSession().connection();


On my test app, it was great, but then with more data I got..

Code:
WARNING: unclosed connection


and eventually at a random point later

Code:
No operations allowed after connection closed


The answer? Garbage Collection!

In the code above, the session is not kept as a variable, thus eventually gets garbage collected at a random point later. At that point the connection is closed and everything goes bad.... The answer is easy

Code:
            Session session = HibernateFactory.getInstance().getFactory().openSession();
            Connection connection = session.connection();


Then all is good.... So even on a simple admin tool, I must be discplined!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.