concept transaction in category iBatis

This is an excerpt from Manning's book iBatis in Action.
Integrity is probably the most important benefit, as without it not much else matters. If our data isn’t consistent, reliable, and correct, then it is less valuable to us—or possibly even useless. Databases achieve integrity by using strong data types, enforcing constraints, and working within transactions.
Transactions are one of the most important concepts to understand when working with a relational database. Few decisions you make will have a greater impact on stability, performance, and data integrity. Knowing how to identify and demarcate the transactions in the system you are building is imperative. In this chapter, we’ll discuss what transactions are and how to work with them.
Now that you know how to start and end transactions in various ways, you might be asking yourself, “Where should I start and end my transaction?” As it turns out, this question of where can be harder to answer than the question of how. As with most difficult questions, the answer is: “It depends.” You’ll find a lot of different answers depending on whom you ask.
Where you demarcate your transaction will determine how long the transaction remains open, as well as how much work is included within the scope of the transaction. Knowing this, it is obvious that performance will suffer with longer-lived, wider-scoped transactions. However, these larger transactions are also somewhat safer in that they ensure the integrity of what is probably a group of related work (otherwise, why would it all be taking place within a single request?). Because it can be difficult to make the decision, here is a simple rule of thumb:
The scope of a transaction should be as wide as possible, but should not extend beyond the scope of a single user action.
For example, in a web application, when a user clicks a button to submit a form, the transaction scope should begin immediately, but by the time the response page is rendered in the user’s browser, the transaction should be complete. In a rich client application, the rule is generally the same. A transaction should include all of the work involved in a single user operation—which is generally represented by a single button click. Another way to think about it is this: a user should never be able to walk away from their computer and leave a transaction open, or incomplete.
So where do we stop and start transactions then? Ideally, you would start the transaction nowhere. In other words, you’d let the container do it. So declaratively you would configure your application such that the transactions were demarcated by the container. Whether you’re using an application server with stateless session beans, or a lightweight container like the Spring Framework, you can configure transactions declaratively. The container will ensure that the transactions are started, committed, and ended appropriately. iBATIS has a unified programming model for transactions, meaning you can and should still use startTransaction(), commitTransaction(), and endTransaction() within your code, even if the container itself will demarcate the real transaction. This allows you to port your persistence code outside of a container and still have a relatively clean transaction story. When configured for EXTERNAL transaction management, iBATIS will let the container handle the transactions.