Quote:
I tried the session.close() method but it gives me an error "Session was already closed"
This is because when you use getCurrentSession() to obtain a session
Code:
Session session = config.buildSessionFactory().getCurrentSession();
then the session is already implicitely closed when ending the transaction
Code:
tx.commit();
But ending the hibernate-session does not automatically mean, that also the regarding connection to the database get closed.
As already stated in my last post, there's a session-pool which puts the connection in pool for being reused.
Please read some documentation about session pooling, to understand the architecture of sessions/connections.
If you want to close all connections at a certain point,
you can for example do it by closing the sessionfactory (or entityManagerFactory if you use the JPA approach)
Code:
sessionFactory.close(); // or entityManagerFactory.close();
this closes also the session-pool which releases then all connections.
After this on mysql there should not be any hibernate related process anymore.