Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Object persistence in Java means saving application data so it remains available after the program that created it stops running. For relational databases, the usual approach is to map Java domain objects to database tables. Jakarta Persistence defines the standard Java API and mapping rules for that work; Hibernate ORM and EclipseLink are examples of providers that implement the standard.

What object persistence means in Java

A Java object normally exists only while the application is running and the object remains reachable. Persistence gives selected application data a longer life by storing it outside the process, commonly in relational database tables. An object-relational mapping (ORM) connects the application’s Java model with that database structure.

Jakarta Persistence defines a standard for persistence management and object/relational mapping in Java environments. The Jakarta Persistence 3.2 specification, published by Jakarta EE on April 10, 2024, describes the goal as providing a standard object/relational mapping facility for Java developers managing relational data with a Java domain model. It applies in both Jakarta EE and Java SE environments and specifies entities, mappings, persistence contexts, EntityManager operations, queries, locking, caching, lifecycle callbacks, and transactions. (Jakarta Persistence Specification Project; Jakarta Persistence 3.2 Specification, Jakarta EE, 2024.)

Jakarta Persistence, JPA, Hibernate, and EclipseLink

These names refer to different layers, not interchangeable products. Jakarta Persistence is the current name of the standard API and specification. JPA remains a familiar shorthand derived from its earlier name, Java Persistence API; when choosing an implementation or reading current documentation, look for Jakarta Persistence and the applicable version.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Name What it is When it matters
Jakarta Persistence The standard API and object/relational mapping specification. Use it as the portability baseline when application code should be less tied to one provider.
Hibernate ORM An implementation of Jakarta Persistence that also offers a native API. (Hibernate ORM project.) Consider it when its framework integrations or provider-specific capabilities suit the application.
EclipseLink An open-source Jakarta Persistence implementation. Consider it as another provider option where its supported environment and capabilities fit.

The Jakarta Persistence project identifies EclipseLink 5 and Hibernate ORM 7 as compatible open-source implementations; that compatibility information was accessed in 2026. Provider compatibility does not mean every provider-specific feature or behavior is identical. (Jakarta EE Persistence project.)

How to choose a provider

Start with the standard API if portability matters, then evaluate providers against the application’s actual constraints. Compare supported Java and database versions, framework or container integration, transaction setup, query and SQL behavior, lazy loading and fetch planning, first- and second-level caching, schema and migration workflow, diagnostics, support options, and upgrade compatibility. A provider-specific capability can be useful, but relying on it may make a later provider change more involved.

How Java classes map to database tables

An entity is a Java class whose persistent state is mapped to relational data. Its state may include basic values, relationships to other entities, embeddable values, and collections. Mapping information can be declared with annotations or in mapping files such as orm.xml; the model does not have to be described in annotations alone. (Jakarta Persistence 3.2 Specification.)

For example, an application might represent a customer as an entity with a persistent identity and a name. A relational mapping connects that identity and name to columns in a table. A relationship from one entity to another represents an association in the Java model and a corresponding relational association. The exact table and column design depends on the mapping and database schema; ORM does not eliminate the need to understand that schema.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A persistence unit groups related persistent classes and their configuration for a database context. An EntityManagerFactory is created for that unit and produces EntityManager instances. An EntityManager works with entities through a persistence context: the managed set of entity instances in which a persistent identity has one unique object instance. The context tracks changes and coordinates their synchronization with the database. (Jakarta Persistence 3.2 Specification.)

Entity lifecycle and EntityManager operations

Understanding whether an entity is new, managed, detached, or removed makes persistence behavior easier to predict. The EntityManager API provides operations for each common transition.

State Meaning Relevant operation or behavior
New (transient) The object is not yet managed by a persistence context. persist(entity) makes a new entity managed and schedules it for insertion as part of synchronization.
Managed The entity belongs to the current persistence context. Change its fields directly. There is no separate explicit update operation; the context tracks managed state for synchronization.
Detached The object is no longer managed by that persistence context. merge(entity) copies state into a managed instance and returns that managed instance. Continue working with the returned object rather than assuming the argument itself became managed.
Removed The managed entity is marked for deletion. remove(entity) marks it for removal, which is synchronized with the database later.

Other useful operations include find to look up an entity by identity, refresh to reload managed state from the database, detach to stop managing an entity, clear to detach all entities in the context, and flush to synchronize pending changes. The exact outcome of an operation depends on the entity’s state and the persistence context. (Jakarta Persistence 3.2 Specification.)

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Flush, queries, and when SQL reaches the database

A change to a managed object does not require an explicit update call. The persistence context holds the change until it synchronizes pending work with the database; that synchronization is called a flush. With the default AUTO flush mode, the provider also flushes before a query whose result could be affected by changes that have not yet been flushed. A flush is synchronization, not itself a commit: transaction completion is a separate concern. (Jakarta Persistence 3.2 Specification.)

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This distinction matters when diagnosing query results, constraint failures, and performance. A write may be sent earlier than an application expects because a query triggers a flush, while other changes may remain pending until a later synchronization point. Use the provider’s SQL and diagnostic logging to inspect actual behavior in the chosen configuration rather than assuming each Java field assignment immediately executes SQL.

Transactions: JTA or RESOURCE_LOCAL

Jakarta Persistence defines two transaction approaches. JTA is generally associated with Jakarta EE container-managed environments and transaction integration. RESOURCE_LOCAL uses an EntityTransaction controlled programmatically and is common in Java SE applications. The right choice depends on the runtime and transaction architecture; these modes are not simply alternate spellings for the same setup. (Jakarta Persistence 3.2 Specification; Jakarta EE Persistence project.)

Keep transaction boundaries explicit: decide which unit of application work must succeed or fail together, begin and complete the corresponding transaction through the selected environment, and handle failures without treating a flush as a commit. Also, do not share an EntityManager between concurrent threads. The specification requires single-threaded access to an EntityManager. (Jakarta Persistence 3.2 Specification.)

When ORM is a good fit—and when to consider SQL-first tools

ORM can reduce repetitive conversion between relational rows and domain objects, and it provides standard entity lifecycle and query APIs. It is a natural fit when application behavior is centered on a domain model and its persistence needs align with entity mappings.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Entity mapping is not automatically the best representation for every workload. Reporting-heavy queries, highly optimized SQL, or operations that do not fit an entity graph may be clearer or more efficient with direct SQL or query-focused tools. Make that choice from the workload and operational needs rather than treating ORM as mandatory for every database interaction.

Quick Recap

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.