|
Answer» Persistent entities in Hibernate can be in any of the below states: - Transient: Objects or entities which are not yet associated with any Hibernate session or have been MAPPED to any database tables are considered to be in the Transient state. These objects exist in the Heap. These objects are SAID to be in the new state. When in this state an Object will not have an identifier. To persist these objects, save, persist or saveOrUpdate methods have to be used.
- Persistent: When an object is associated with a database table, it is said to be in persistent state. A Persistent object is MANAGED by the CURRENT persistence context. Any change made to this object is propagated in the database with which the object is associated. Associating a transient entity with a session will make it persistent
- Detached: An object or entity is said to be in the detached state when the persistence context it is associated with is closed. In this state, any changes made to the object are not tracked and the database with which it is associated, is not synchronized automatically. A detached object can be reattached to a persistence context if and only if there is no other object associated with the database row in the current Hibernate session.
- Removed: When persistent objects are handed over to remove() method, they are said to be in the Removed state. These objects are only marked for removal.
|