Do I need to manually close a connection obtained from a hibernate session?
If I do this, will I be closing one of the connections in the connection pool?
Will hibernate automatically close the connection if I do not?
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
String query = "sql query";
try {
Session session = this.sessionFactory.getCurrentSession();
con = session.connection();
ps = con.prepareStatement(query);
rs = ps.executeQuery();
while (rs.next()) {
//read result set
}
} catch (SQLException exp) {
log.error("Error: ", exp);
} finally{
if(ps != null)
ps.close();
if(con != null)
con.close(); //Is this required?
}