Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What is the difference between a session and a transaction ? #hibernate #jpa

I'm not sure if I completly understand the difference between the use of a session and the use of a transaction

user-image
Question added by Usama Saad , Senior Software Engineer (Java) , Saudi Catering Company
Date Posted: 2013/10/02
Hatim Laxmidhar
by Hatim Laxmidhar , Self Employed , The Way It Works

Let me explain what is a session and transaction with analogy.

You go to a market for shopping. This means you have created a session in market.

Now you are going to a shopkeeper to purchase item X. Here your transaction starts, you pick the item, pay the amount to the shopkeeper, get the change back and keep it in your pocket and leave the shop with item X. Your transaction is over.

You are still in the market, so your session is still alive.

You go to another shop or same shop to purchase item Y or Z. you are starting another transaction in the same session.

Session will end once you leave the market.

You logged in (created a session).

Transaction:

Searched for the items and picked one item, provided shipping and billing details, paid the amout, and checkout. 

Transaction Over.

You have done another shopping in the same manner

Another transaction over.

You logged out.

Session Ends

Same works with hibernate/jpa/database or any other computer programming.

Note: JPA do not have session, entitymanager acts as session. 

Session: Physical connection to your DB.Transaction: Unit of work done with your DB.

P A Cariappa Appaiah
by P A Cariappa Appaiah , back office executive , Inspire Hond

Session refers to , just visiting the market place, to see, the goods , available , and deciding whether, to purchase or not.

 

Transaction : Refers to , were in , purchasing the things, by giving monetary value. 

In simple terms Session contains multiple transactions. 

Mamdouh AlSharif
by Mamdouh AlSharif , Freelance Data Manager, Manipulator and Analyst , Freelance

(in general)

A transaction is something you do on your data on your database. Like; adding new records,  and (deleting & modifying) exciting records.

 

A session is a unique communication environment created between you and the database to insure your transactions are save and not mismatched with other sessions. It is essential to have a session specially in a multi-user and multi-USE environment. For example; sometimes, you need to make a transaction from one PC while you are running a report from another PC. The database to insure accurate responses will establish different sessions for each of them and treat each session as a different user (generally speaking).

Syed Ali Aqdas Shah
by Syed Ali Aqdas Shah , Software Engineer(JAVA Oracle Developer) , Softverx

Session is a common interface and a way of communication between java application and Hibernate ORM that can have one or many transactions. basically a transaction is a single atomic operation that may be insert, update, delete. in case of interupt the transaction is roll back.

Saubia Zarnain
by Saubia Zarnain , Senior Software Engineer , Oracle Financial Services Software limited

A session is what you use to interact with the database.

A transaction is used to specify boundaries for the session to operate within.

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.