If the Session got the connection from a JDBC pool, it will return it on close(), otherwise you can re-use the Connection you passed in with SessionFactory.openSession(myConnection).
Don't manually commit() the the Connection. It is possible, but much more convenient to use the Hibernate Transaction API:
Session session = sf.openSession(); // Get it from JDBC pool
Transaction tx = session.beginTransaction();
// do some work here
tx.commit();
session.close();
Throw in some Exception handling and you are fine.
_________________ JAVA PERSISTENCE WITH HIBERNATE http://jpwh.org Get the book, training, and consulting for your Hibernate team.
|