-->
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: Calling session.close() from Object.finalize()
PostPosted: Mon Aug 30, 2004 2:51 pm 
Newbie

Joined: Wed Nov 12, 2003 1:11 pm
Posts: 3
Location: Brazil
Hi all,

My program call session.close() from Object.finalize() method, like this:

public class Facade {

private Session session;

public Facade() {
this.session = HibernateHelper.getSession();
}

...

protected finalize() throws Throwable {
if ( session != null )
session.close();
}

}

However, the session log the follow message:

5:20:34,249 WARN [SessionImpl] unclosed connection

I know that this message happens when the garbase collector call
finalize() from the session object and the session is still open.

May this cause any problem?
Must my program call session.close() from other place?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 30, 2004 4:43 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
Relying on Object.finalize() to implement you Hibernate session/transaction handling is certainly not a good idea !

Start by having a look at http://blog.hibernate.org/cgi-bin/blosxom.cgi/2004/02/18/

Then think about how can you detect and recover from any error than can occur during the tx.commit() and session.close() ...

Finally, don't forget you don't have any control on when the garbage collector will call you finalize() method. This can be long after your thread - to which your ThreadLocal session is associated - has completed its work... Hence the message you get saying your connections haven't been closed.


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.