I have noticed in many examples that the user begins and closes a transaction when all there is in the operation is a simple query. Can some one explain why the transaction is established. Is there any benefit in not creating a transaction?
Example code to illustrate:
Code:
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
result = session.createCriteria(messages.class).list();
tx.commit();
tx = null;
} catch (HibernateException e) {
log.error("Could not acquire list of Messages", e);
}
finally {
session.close();
}