Lifecycle Of Hibernate
Posted By : Sameer Grover | 30-Sep-2015
Hibernate handles the state of the objects to perform operation on the database.
There are 3 different states of objects in Hibernate :-
When a instance of an object is created then that object will firstly in transient state.It is the first step of Hibernate Lifecycle.
When an object is in transient state, it means its not connected to the database and not representing any row. It will behave like a ordinary pojo class and If we modify the data
of a pojo class object, when it is in transient state then it doesn’t effect on the database table.
To Change the state of an object from transient to persistent, we need to put that object into the session, so that it can represent a row of the table.
When object is in persistent state hibernate will track the object and any changes with that object will effect the database.
Object in persistent state will always bind with the unique session & keep in persistent state till the session expires.
When the session closes the object in the session then comes to the detached state and disconnect with the database,This is the final and dead state
of an object in hibernate, any changes with that object cant reflect the database. but hibernate allows that detached object to bind with the new session.
detached object can again convert into persistent state.