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 ...

Get Learning PostgreSQL now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.