20 January 2021

Transaction state

Persist

  • Hibernate Persist will save within transaction. 
  • Will not generate the Id immediately. And the return type of the method is void
  • Data persistence will happen when it’s needed.
  • Only transaction commit is enough to save both parent and child
  • Object is associated with any unique session then it’s in persistent state.
  • Persistent instance may turn back to transient by calling delete method.
  • Any instance returned by get or load method is persistent state
  • persist() method guarantees that it will not execute an INSERT statement if it is called outside of transaction boundaries.

Transient

  • When an object is never persisted or associated with the session it’s in Transient state.
  • Transient instance may be called persistent when its save , persist or saveOrUpdate method.

Detached

  • Object is persistent and not associated with any session then it’s in detached state
  • Detached instances may be made persistent by calling update (), saveOrUpdate (), lock () or replicate().
  • The state of a transient or detached instance may also be made persistent as a new persistent instance by calling merge ().

No comments:

Post a Comment

Most views on this month