From the following source : hibernate transaction eg.
It is written that, A typical transaction should use the following idiom:
Session sess = factory.openSession();
Transaction tx;
try {
tx = sess.beginTransaction();
//do some work
...
tx.commit();
}
catch (Exception e) {
if (tx!=null) tx.rollback();
throw e;
}
finally {
sess.close();
}
My question is what does tx object have if it goes in catch block i.e. any exception occurs and is this the result of tx.commit()?? And if yes, then how, because it returns nothing. I mean to ask that when and where the value of tx is changing and to what?
Quesion 2) Is it necessary to begin transacion in case of read only transactions i.e. select queries ..