My application has long running transactions and hence I tried the option session.close() at the end of every method to ensure that the connection objects are not held indef
I am using JTA transaction in my application. In hibernate.cfg.xml, I have set connection.release_mode to auto (default) and connection.autocommit to true.
Could you try to define the hibernate.connection.release_mode property to after_statement explicitly? I know this is supposed to be the default but, depending on your context (could you be using Spring?), auto might not behave as expected (see here and here).
For reference, here is what the Table 3.4. Hibernate JDBC and Connection Properties writes about the property hibernate.connection.release_mode:
Specifies when Hibernate should release JDBC connections. By default, a JDBC connection is held until the session is explicitly closed or disconnected. For an application server JTA datasource, use
after_statementto aggressively release connections after every JDBC call. For a non-JTA connection, it often makes sense to release the connection at the end of each transaction, by usingafter_transaction.autowill chooseafter_statementfor the JTA and CMT transaction strategies andafter_transactionfor the JDBC transaction strategy.e.g.
auto(default) |on_close|after_transaction|after_statementThis setting only affects Sessions returned from
SessionFactory.openSession. For Sessions obtained throughSessionFactory.getCurrentSession, theCurrentSessionContextimplementation configured for use controls the connection release mode for those Sessions. See Section 2.5, “Contextual sessions”
If it doesn't help, please add more details about your environment and configuration (Spring?), how you get the session, etc.
if you are using the JDBCTransactionManager, the connection will be returned to the connectionpool when the transactions ends.