Friday, October 7, 2016

Hibernate life cycle



1. Transient State:
    A New instance of  a persistent class which is not associated with a Session, has no representation in the database and no identifier value is considered transient by Hibernate:
UserDetail user = new UserDetail();
user.setUserName("Dinesh Rajput");
// user is in a transient state
They can become into persistent objects through the save method calls of Session object.


2. Persistent State:
    A persistent instance has a representation in the database , an identifier value and is associated with a Session. You can make a transient instance persistent by associating it with a Session:
Long id = (Long) session.save(user);
// user is now in a persistent state

3. Detached State:
    Now, if we close the Hibernate Session, the persistent instance will become a detached instance: it isn't attached to a Session anymore (but can still be modified and reattached to a new Session later though).
session.close();
//user in detached state
The detached object can be reattached after certain time to another object in order to become persistent again.

Image result for hibernate lifecycle



No comments:

Post a Comment

உப்பு மாங்காய்

சுருக்குப்பை கிழவி. சுருக்கங்கள் சூழ் கிழவி. பார்க்கும் போதெல்லாம் கூடையுடனே குடியிருப்பாள். கூடை நிறைய குட்டி குட்டி மாங்காய்கள். வெட்டிக்க...