Transaction is the process of performing multiple database operations as one unit with all nothing criteria.
I:e when all the database operations in the unit are successful then transaction is successful and should be committed. When any one database operation in the unit are failed then transaction are failed and should be rolled back.

When you implement transaction property in your application it guarantees ACID properties.
A- Atomicity
C- Consistency
I- Isolation
D- Durability

Atomicity : It will give you a guarantee that the whole work will be performed as a unit. If one part of transaction fails then entire transaction fails.

Consistency : Consistency is about ensuring that any transaction will bring the database from one valid state to another.

Isolation : Many transaction may run concurrently. These concurrently running multiple transaction may disturb other transaction that is multiple transaction should run isolately.

Case A : Consider the case where multiple transaction running concurrently and using multiple rows of account table.
tx1 -> 101
tx2 -> 102
tx3 -> 103

1. withdraw from 101
2. withdraw from 102
3. withdraw from 103

Case B : Consider the case where multiple transaction running concurrently and using single account row of account table.
acc no: 99

1. transfer(withdraw)
2. bank teller(withdraw(deposite))
3. loan EMI(withdraw)
in case B you may get some problem which is called as transnational concurrency problems.

  1. Dirty read problem.
  2. Repetable read problem.
  3. Phantom read problem. 
To avoid these problems, you have to apply one of the following required transactional isolation levels.

  1. READ_UNCOMMITTED
  2. READ_COMMITTED
  3. REPETABLE_READ
  4. SERIALIZABLE
Durability : Yoyr enterprise data should be available for long time as long as your enterprise is running. You have to protect your data from crashes, failures, you have to implements your proper backup and recovery mechanism and proper loging mechanism.

Dirty read problem :

  • When transaction reads the dirty value(modified but not committed) then you may get some inconsistent result.
  • To avoid dirty read you have to lock the column(cell).
  • To lock the column you have to apply isolation level called READ-COMMITTED.
Repetable read problem :

  • When a transaction is reading the same row repeatedly, you may get different set of values in different reads. this kind of problem is called repeatable read problem.
  • To avoid repeatable read problem you have to lock the row.
  • To lock the row you have to apply isolation level called REPEATABLE-READ.
Phantom read problem :

  • When a transaction is reading the set of row repeatedly you may get different set of rows in different reads this kind of problem is called phantom read problem. 
  • To avoid phantom read you have to lock the entire table.
  • To lock the table you have to apply isolation level called SERIALIZABLE.
Types Of Transaction :

  1. Local transaction :
    When a single database is participating in the transactional operation then it is called local transaction.
  2. Distributed transaction :
    When two or more database are participating in the transaction operations then it is called as distributed transaction.
Types Of Transaction :

  1. Flat transactions : A simple transaction that perform one or more operations as a unit operation.
  2. Nested Transactions : as the word nested says one transaction under another transaction.


Related Posts:

  • Alternatives of Open Session In View(OSIV) Today I am going to tell you other alternative you can do in order to avoid LazyInitializationException: Session has been closed. If you are using SPRING with HIBERNATE that you can take the advantages of IOC and AOP. These … Read More
  • Hibernate index Why Hibernate  Hibernate Architecture  Hibernate Session Factory Hibernate Session Hibernate Cache  Hibernate Transaction Hibernate Transaction Management  Open Session In View (OSIV) Alternative to … Read More
  • Hibernate Fetching Strategies Today i am going to tell you what are the Hibernate Fetching Strategies and how to use that in order to tune the performance of your applications. So these are the fetching strategies in hibernate : join fetching(fetch="jo… Read More
  • What is n+1 problem and how to solve it N+1 is one of the most famous question among java developers. It will give some performance issue if you where working on a large project. So it's better to resolve it using some below techniques. What is n+1 problem ? Ans… Read More
  • Open Session In View(OSIV) Once the session is closed you can not be able to access the data from detached object and if you do you will get a LazyInitializationException: Session has been closed. It means that your session and session transaction is… Read More

2 comments:

  1. This topic is really cool and very useful
    ------------
    شركة عزل اسطح بمكة

    ReplyDelete
  2. Thanks for the post, I am techno savvy. I believe you hit the nail right on the head. I am highly impressed with your blog. It is very nicely explained. Your article adds best knowledge to our Java Online Training from India. or learn thru Java EE Online Training Students.

    ReplyDelete

Blog Archive

Ads 468x60px

.

Ads

.

Featured Posts

Popular Posts

Like Us On FaceBook

Total Pageviews

201978

Online Members

Live Traffic