Hibernate object states


There are three types of Hibernate object states.
1.Transient state:
An object is in transient state if it is just created and not associated with session.
Example :
Employee e1=new Employee();
e1.setId(115);
e1.setFirstName(“Rahul”);
e1.setLastName(“Thakur”);

2.Persistent state:
An object is in persistent state if session is opened and you saved the instance of the object or get the object from the database.
Example :
session.save(e1);

3.Detached state:
An object is in detached state if session is closed. After detached state object come to Persistent state.
Example :
session.close();