-->
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: connection and session closing
PostPosted: Fri Mar 02, 2012 4:15 am 
Newbie

Joined: Fri Mar 02, 2012 4:10 am
Posts: 1
I have the following code in the Try bloc :

// Session variable
Session session = null;
// Connection variable
Connection conn = null;

try {
...
// Get hibernate session
session = getHibernateTemplate().getSessionFactory().openSession();
// Get connection frojm session
conn = session.connection();
...
}catch{
...
}


And in the finally bloc i want to bloc all the related object of the connection with the database.

the closing of session makes us to close the connection ? or we have to have to close the connection before ?

Solution 1 :

finally{
try{if (conn!=null) conn.close();}ctach{}
try{if (session!=null) session.close();}catch{}
}


Solution 2 :

finally{
try{if (session!=null) session.close();}catch{}
}


In case of one of the two solutions before, can you explain the relationship between session and connection specially through pool way.


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.