File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes transaction when we Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "transaction when we "select" data from db ?" Watch "transaction when we "select" data from db ?" New topic

transaction when we "select" data from db ?

Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798

Do we need a transaction when we "select" data from db ? The coding is below, though it is hibernate version.


David O'Meara

Joined: Mar 06, 2001
Posts: 13459

Depends what you want to do with the data. If you plan on updating the data but there was no transaction, then there would be no guarantee on the data at the point you go to save your records.
Martin Vajsar

Joined: Aug 22, 2010
Posts: 3733

This may strongly depend on the database. In Oracle, for example, you can start the transaction in serializable mode (or read-only mode for that matter, though JDBC does not directly support read-only transactions) and all your selects will return data as they existed at the time the transaction started. This may be important in regard to the consistency of data being read.

In other databases the transaction (and its isolation level) might affect the results in different ways.
I agree. Here's the link:
subject: transaction when we "select" data from db ?
It's not a secret anymore!