Step 4- States of objects in hibernate

Hibernate object states-


1-Transient state-

  • When object is just created and has no primary key, the state is called transient.

2-Persistent state-

  • When session is opened and object is just saved in database [using save, saveOrUpdate, persist, merge etc method]
  • or retrieved from the database [using get, load etc method]. This state is called persistent.

3-Detached state-

  • When the session was closed, the state changes to detached.
  • or evict() , clear() etc methods are applied, The object is detached from its session.