I have the following method that inserts a large batch of records every few seconds. After some time of running I get errors like the following:
ERROR: C
Rather make a generic method for any object type and pass the object. Add logic of any List too.
public void save(Object obj) {
Session session = null;
Transaction transaction = null;
try {
session = sessionFactory.getCurrentSession();
transaction = session.beginTransaction();
session.save(obj);
session.flush();
transaction.commit();
} catch (JDBCException jde) {
logger.fatal("Error occured in database communication", jde);
transaction.rollback();
throw new RuntimeException(jde);
} finally {
if (session.isOpen()) {
session.close();
}
}
}