Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.
I'm not sure if I completly understand the difference between the use of a session and the use of a transaction
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.
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.
(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).
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.
A session is what you use to interact with the database.
A transaction is used to specify boundaries for the session to operate within.