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
You probably have begun a transaction, and trying to begin another one without having committed or rollbacked the previous one. The idiom when using programmatic transaction demarcation is the following one:
Transaction transaction = null;
try {
session = HibernateUtil.getSession();
transaction = session.beginTransaction();
... to do ....
transaction.commit();
}
catch (RuntimeException e) {
transaction.rollback();
throw e;
}
Add the following property in your Hibernate.cfg.xml
thread