From here:
http://www.hibernate.org/403.html
I have concluded that you DO NOT need to demarcate a transaction around a READ operation (or many consecutive read operations). Hibernate suggests that you do this just to make things more complicated than they should. OF COURSE, if you are doing an WRITE (insert/update/delete) then you need a transaction, but my post is about a READ (select) and about the HelloWorld hibernate code that uses a transaction around a simple select operation.
If Hibernate is so worried about this, it should rollback or commit any open transaction on a session close. Why complicate a simple stuff?
Look here: (this is what the above link states)
Look at the following code, which accesses the database without transaction boundaries:
Code:
Session session = sessionFactory.openSession();
session.get(Item.class, 123l);
session.close();
By default, in a Java SE environment with a JDBC configuration, this is what happens if you execute this snippet:
1. A new Session is opened. It doesn’t obtain a database connection at this point.
2. The call to get() triggers an SQL SELECT. The Session now obtains a JDBC Connection from the connection pool. Hibernate, by default, immediately turns off the autocommit mode on this connection with setAutoCommit(false). This effectively starts a JDBC transaction!
3. The SELECT is executed inside this JDBC transaction. The Session is closed, and the connection is returned to the pool and released by Hibernate — Hibernate calls close() on the JDBC Connection. What happens to the uncommitted transaction?
The answer to that question is, “It depends!” The JDBC specification doesn’t say anything about pending transactions when close() is called on a connection. What happens depends on how the vendors implement the specification. With Oracle JDBC drivers, for example, the call to close() commits the transaction! Most other JDBC vendors take the sane route and roll back any pending transaction when the JDBC Connection object is closed and the resource is returned to the pool.
Obviously, this won’t be a problem for the SELECT you’ve executed!
Yes! The above sentence in red was said by Hibernate Documentation, not me. So I am concluding I am correct when I say that explicit using a transaction for a read operation is a waste of simplicity.