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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.