Hibernate Objects States And Lifecycle

Hibernate has provided three different states for an object of a pojo class. pojo class is nothing but a class that represents a table in database .These three states are also called as life cycle states of an object in hibernate.

There are three types of Hibernate object states.

  • Transient state
  • Persistent state
  • Detached state

Transient state

An object which is not associated with hibernate session and does not represent a row in the database or there is no reference of it in the database is considered as transient, that means its just an normal object.

Persistent state

An object is in the persistent state if it has some reference in the database i.e it represent one row of the database and it is associated with the unique Session. If any changes are made to the object then hibernate will detect those changes and effects will be there in the database .

Detached state

Object which is just removed from hibernate session is called as detached object and state of that object is detached  state.

Leave a comment