Hibernate States .
What are the state of the object in the Hibernate?
There are three state in Hibernate a). Transient State b). Persistent State c). Detached State
1. Transient 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:
Now, if we close the Hibernate Session, the persistent instance will become a detached instance: it isn't attached to aSession anymore (but can still be modified and reattached to a new Session later though).
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("bhringi");
Note- user is in a transient state
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);
Note- user is now in a persistent state3. Detached State:
Now, if we close the Hibernate Session, the persistent instance will become a detached instance: it isn't attached to aSession anymore (but can still be modified and reattached to a new Session later though).
session.close(); Note--user in detached state
Hibernate States .
Reviewed by Mukesh Jha
on
2:30 AM
Rating:
Reviewed by Mukesh Jha
on
2:30 AM
Rating:


No comments:
Add your comment