The documentation for the hibernate.connection.release_mode property may be helpful:
Quote:
Specify 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, you should use after_statement to 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 using after_transaction. auto will choose after_statement for the JTA and CMT transaction strategies and after_transaction for the JDBC transaction strategy.
eg. auto (default) | on_close | after_transaction | after_statement
Note that this setting only affects Sessions returned from SessionFactory.openSession. For Sessions obtained through SessionFactory.getCurrentSession, the CurrentSessionContext implementation configured for use controls the connection release mode for those Sessions. See Section 2.5, “Contextual Sessions”
My understanding is that if hibernate.connection.release_mode is set to auto, connections are obtained when the session is opened, and released when the session is closed. If it's set to after_transaction, I think it doesn't obtain a connection until session.beginTransaction (and then releases it after transaction.commit()).
Anyway, obtaining a connection should not be expensive because you should be using a connection pool. The connections have already been created, you are just checking it out of the pool (an inexpensive operation).