I read about Hibernate for a while, but I cannot understand one concept regarding Transaction .
On some sites I visited, Select statements are in transaction mode like this.
public List<Book> readAll() { Session session = HibernateUtil.getSessionFactory() .getCurrentSession(); session.beginTransaction(); List<Book> booksList = session.createQuery("from Book").list(); session.getTransaction().commit(); return booksList; }
While on some site it does not protect the use of a transaction in Select statements:
public List<Book> readAll() { Session session = HibernateUtil.getSessionFactory() .getCurrentSession(); List<Book> booksList = session.createQuery("from Book").list(); return booksList; }
I think with whom I should follow. Are transactions necessary for Select Statements or not?
source share