Hibernate Interview Questions – Part 5

Hibernate Interview Questions – Part 5
Part 1, Part 2, Part 3, Part 4
Persistent Objects and Transactions

Different Object States in Hibernate?

An object created using new Operator is known in Transient State. This object is not associated with database.

When a Transient object with values are stored in database, then the object is said to be in Persistent State.

Detached State:
When an object is saved in the database and the hibernate session is closed, The object is said to be in Detached State

What is a Transaction?
Transaction is a sequence of operations performed.

Properties of Transactions?
Every transaction should have the following ACID properties,
Atomic : All the modifications to be performed or none to be performed
Consistency: All data should be consistent once the transaction has been completed
Isolation: Every transaction should be Isolated from another transaction
Durability: Data change in a system after the transaction is completed should remain permanent in the System.

States of Transactions:
when transaction is created and ready for execution.

Partially Committed:
When all the operations are performed but the transaction is not yet committed.

When transaction is failed and cannot proceed further.

Transaction is failed and the operations of transactions are rolled back.

Transaction is success and all the changes are committed and saved in database.

When transaction is completed successfully or when transaction is failed this state occurs.

Methods to Configure Transactions:
void begin():
Starts the transaction.

void commit():
Ends the work.

void rollback():
Reverse the changes.

boolean wasCommitted():
checks whether the transaction is committed or not.

boolean wasRolledBack():
checks if transaction is rolledback or not.


Leave a Reply

Your email address will not be published. Required fields are marked *