States of Hibernate instance
1. Transient
- Object just created but has no primary key / identifier
- Not associated with any session (persistence context)
- doesn’t represent any row of the database
2. Persistent
- Instance associated with a session , when you
- just saved instance in DB , or
- retrieved instance from the DB
- represents one row of the database
Changes to persistent objects are tracked by hibernate and are saved into database when commit call happen.
3. Detached
- Instance was associated with a session which has been closed
- Associated with a session in past but not currently - No longer persistent
After detached state, object comes to persistent state if we call lock() or update() or saveOrUpdate() method - reattach object to hibernate session

No comments:
Post a Comment
Note: only a member of this blog may post a comment.