Working with entities
In addition to adding a layer of abstraction above the database system, Hibernate introduces state management to entity objects. This shifts the focus of development from executing SQL statements to managing the state of entities.
States of an entity
In Hibernate, an entity can have one of the following four states:
- Transient: This is the initial state of an entity after instantiation. It does not have a representation in the database yet, and is not associated with a session.
- Persistent: An entity that is represented in the database and has an identifier assigned. A persistent entity is tied to a session.
- Detached: When closing the underlying session, a persistent entity will be detached. It will still exist as an object, but updates to it will not be reflected in the database. It can be reattached to a session later to persist it again.
- Removed: An object that is scheduled for deletion.
The transitions between the states are triggered by calling various methods on the session...