Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 205193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:32:05+00:00 2026-05-11T17:32:05+00:00

There seem to be very different opinions about using transactions for reading from a

  • 0

There seem to be very different opinions about using transactions for reading from a database.

Quote from the DeveloperWorks article Transaction strategies: Models and strategies overview:

Why would you need a transaction if
you are only reading data? The answer
is that you don’t. Starting a
transaction to perform a read-only
operation adds to the overhead of the
processing thread and can cause shared
read locks on the database (depending
on what type of database you are using
and what the isolation level is set
to).

As a contrary opinion there is the following quote from Hibernate documentation Non-transactional data access and the auto-commit mode

Our recommendation is to not use the
autocommit mode in an application, and
to apply read-only transactions only
when there is an obvious performance
benefit or when future code changes
are highly unlikely. Always prefer
regular ACID transactions to group
your data-access operations,
regardless of whether you read or
write data.

There is also a similar debate on the EclipseLink mailing list here.

So where lies the truth? Are transactions for reading best-practice or not? If both are viable solutions, what are the criteria for using transactions?

As far as I can see it only make a difference if the isolation level is higher than ‘read committed’. Is this correct?

What are the experiences and recommendations?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:32:05+00:00Added an answer on May 11, 2026 at 5:32 pm

    Steven Devijver provided some good reasons for starting transactions even if the operations are only going read the database:

    • Set timeouts or lock modes
    • Set isolation level

    Standard SQL requires that even a query must start a new transaction if there is no transaction currently in progress. There are DBMS where that is not what happens – those with an autocommit mode, for example (the statement starts a transaction and commits it immediately the statement completes). Other DBMS make statements atomic (effectively autocommit) by default, but start an explicit transaction with a statement such as ‘BEGIN WORK’, cancelling autocommit until the next COMMIT or ROLLBACK (IBM Informix Dynamic Server is one such – when the database is not MODE ANSI).

    I’m not sure about the advice never to rollback. It makes no difference to the read-only transaction, and to the extent it annoys your DBAs, then it is better to avoid ROLLBACK. But if your program exits without doing a COMMIT, the DBMS should do a ROLLBACK on your incomplete transaction – certainly if it modified the database, and (for simplicity) even if you only selected data.

    Overall, if you want to change the default behaviour of a series of operations, use a transaction, even if the transaction is read-only. If you are satisfied with the default behaviour, then it is not crucial to use a transaction. If your code is to be portable between DBMS, it is best to assume that you will need a transaction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Duplicate : Using a regular expression to validate an email address There seem to
What references offer a good summary/tutorial for using RDF/OWL? There seem to be enough
There seem to be many ways to define singletons in Python. Is there a
There seem to many ways to skin this particular cat - but which is
There seem to be two rival Eclipse plugins for integrating with Maven: m2Eclipse and
There seem to be a number of weird things one could do if one
There seem to be so many color wheel, color picker, and color matcher web
There seem to be many options to create an XML document in .NET. What's
There seem to be many excellent web frameworks for Python. Has anyone used any
Although I deeply fell in love with the MVVM pattern there seem to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.