Hibernate Transaction Management Example
A transaction basically speaks to a unit of work. In such case, on the off chance that one stage comes up short, the entire exchange fizzles (which is named as atomicity). An exchange can be portrayed by ACID properties (Atomicity, Consistency, Isolation and Durability).
Transaction Interface in Hibernate
In rest system, we have Transaction interface that characterizes the unit of work. It keeps up deliberation from the exchange usage (JTA,JDBC).
A exchange is related with Session and instantiated by calling session.beginTransaction().
The techniques for Transaction interface are as follows:
- void begin() begins another transaction.
- void commit() closes the unit of work except if we are in FlushMode.NEVER.
- void rollback() powers this exchange to rollback.
- void setTimeout(int seconds) it sets an exchange break for any exchange begun by an ensuing call to start on this instance.
- boolean isAlive() checks if the exchange is still alive.
- void registerSynchronization(Synchronization s) registers a client synchronization callback for this transaction.
- boolean wasCommited() checks if the exchange is commited successfully.
- boolean wasRolledBack() checks if the exchange is rolledback successfully.
Example of Transaction Management in Hibernate
In rest, it is smarter to rollback the exchange if any special case happens, with the goal that assets can be free. How about we see the case of exchange the board in hibernate.