Sunday, June 6, 2021

Hibernate object life cycle state

Hibernate life cycle contains the following states: 

1.Transient

2.Persistent

3.Detached

1.Transient:The initial states of an object.when an object is created it entered into transient state.It is not associated with any session.So this state is not related to any db . In transient state object reside into heap memory.

Ex: Person person = new Person();//Here person is in transient state

person.setName("Lokman hossain");

2.Persistent:As soon as the object associated with the session ,it entered in the persistent state.Any modification in this state will effect the database .

ex:session.save(person);

session.persist(person);

session.saveOrUpdate(person);

session.merge(person);

session.lock(person);

3.Detached:When the session is closed the object entered into detached state.Changes will not effect the database.Object is no longer associated with hibernate session.

ex:session.close();

session.clear();

session.detach();

session.evict();


No comments:

Post a Comment

Fluent interface pattern

 public class UserConfigurationManager {     private String userName;     private String password;     private UserConfigurationManager() { ...