I need to make sure many concurrent users be able to access the database. Although after each commit I close the session but sometimes my code runs into following error, but
Use session.beginTransaction() instead of session.getTransaction().begin() in your code. You need to begin a new unit of work, so beginTransaction will begin a new transaction. So your code will look like:
session = HibernateUtil.getSession();
Transaction transaction = session.beginTransaction();
... to do ....
transaction.commit();
Click Here to get more information about beginTransaction(); method.
I think that will resolve your issue. Please let me know if issue persists.