Hibernate Entity Object States | LifeCycle States

Hibernate Entity persistent object can be in four different states transient, persistent, detached.

Hibernate basically works on a java object and that java object when linked with hibernate annotations passes through these states in its complete lifecycle.

Let’s look at all the Three lifecycle states:

1. Transient Object

An object is transient if it has just been instantiated using the new operator, and it is not associated with a Hibernate Session.

Hibernate will detect any changes made to an object in persistent state and synchronize the state with the database when the unit of work completes.

2. Persistent Object

Persistent objects exist in the database, and Hibernate manages the persistence for persistent objects.

3. Detached Object

A detached instance is an object that has been in the persistent state, but its Session has been closed. The reference to the object is still valid, of course, and the detached instance might even be modified in this state.

Summary

In this article we read about the Hibernate Entity Object States or the LifeCycle States, how hibernate maintains the lifecycle of an entity object.
I hope you liked the article !