Hi All,
On queries that only return data and do not save, update, or delete data, is it nessacary to do a tx.rollback() in the catch section if the createQuery or tx.commit() fail.
Also, It is my understanding that tx.commit() is required on read only queries, because it cause a sync between the database and the session. Is this correct?
Thanks,
Ron
Hibernate version:3
Code between sessionFactory.openSession() and session.close():
Session session = HibernateSessionFactory.currentSession();
Transaction tx = session.beginTransaction();
ContactInfo contact = null;
try{
contact = (ContactInfo) session.createQuery("from ContactInfo a where a.login =:userLogin")
.setString("userLogin", userlogin)
.uniqueResult();
tx.commit();
}catch(Exception e){
System.err.println("ERROR: Exception in getContactInfo(String) at session.createQuery. Details: "+e);
}finally{
HibernateSessionFactory.closeSession();
}
Name and version of the database you are using:
mySql 5
|