-->
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.  [ 4 posts ] 
Author Message
 Post subject: Session.close() or Session.connection().close()?
PostPosted: Wed Nov 16, 2005 10:31 pm 
Newbie

Joined: Wed Aug 10, 2005 5:03 am
Posts: 4
Hi,

I'm writing a 3-tier app with hibernate persistence as part of web-application on Sun Appserver behind a web service that is being consumed by a Swing client from a remote location. The web service endpoint exposes only a couple of persistence-related methods that are then delegated to a POJO interface implemented with hibernate:
-void saveObject(MyPOJO) //saveOrUpdate
-MyPOJO openObject()

Essentially I am doing session per web service call: each of these methods starts with:
session = HibernateUtil.sessionFactory.openSession();
//do db work
//ends with
finally
{
session.close();
}

I saw someone use the following to close each session as part of unit test:
session.connection().close();
session.close();

Why? Should I be doing that at the end of each web service call?

Also should I be calling something immediately prior to application undeployment?

thanks
-nikita

Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.05

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 2:00 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
forget session.connection().close() , it's not needed and it closes the jdbc connection anyways. as far as undeployment, the only thing that comes to mind is sessionFactory.close() ;


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 3:21 am 
Beginner
Beginner

Joined: Sat Oct 22, 2005 11:16 pm
Posts: 40
Simple answer: Do not use session.connection.close.

Explanation: That will close the JDBC link itself. That means your application is getting itself involved in managing the JDBC links. That is not right. Whatever container you are running in will handle that for you. For example, Tomcat manages its own pools. If you nuke connections by yourself, that disrupts whatever Tomcat is doing. I don't know if that will actually cause failures but it will degrade the performance of Tomcat's pooling.

The only exception to this is if you have created the session by providing it with a JDBC connection, like this:

Code:
session = sessionFactory.openSession(myJdbcConnection);


which is rarely-used. You might use that in a stand-alone application, maybe, but it's rare.

So, no, do not call session.connection.close.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 3:22 am 
Beginner
Beginner

Joined: Sat Oct 22, 2005 11:16 pm
Posts: 40
To put it another way, "if you have to ask, the answer is no."


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.