Java persistence frameworks

Java persistence approaches make different choices about SQL control, object mapping, type safety, runtime complexity, and framework integration. No option is universally best. The useful question is which responsibilities a particular application and team want the library to own.

Three overlapping approaches to Java persistence

These groups describe the center of gravity of each tool, not hard boundaries. Framework integrations can use direct SQL or delegate to an ORM. A project can also combine approaches, such as jOOQ for reporting queries and Hibernate for transactional domain work.

Direct SQL and SQL-centric

JDBC, Jdbi, MyBatis, and jOOQ keep SQL or the SQL query model visible. They differ in how much binding, mapping, query construction, and compile-time checking they add.

ORM

JPA, Hibernate, and EclipseLink center persistence on entities and an object model. JPA is a specification. Hibernate and EclipseLink are implementations, each with features beyond the specification.

Framework-integrated

Spring JDBC, Spring Data JPA, Micronaut Data JDBC, and Micronaut Data JPA integrate persistence with a broader application framework, including configuration, repositories, and transactions.

Spring Data JPA commonly delegates to Hibernate, though another JPA provider can be used. Micronaut Data similarly offers distinct JDBC and JPA integrations.

How the main persistence approaches differ

Direct SQL and SQL-centric tools

JDBC

Advantages: a standard API, direct access to SQL and driver behavior, and no additional persistence abstraction.

Limitations: statement lifecycle, parameters, result-set mapping, errors, and transaction boundaries need application code or supporting utilities.

Common uses: small data-access layers, specialized database operations, bulk work, and foundations for higher-level libraries.

Jdbi

Advantages: stays close to SQL while reducing JDBC ceremony through named parameters, row mappers, managed handles, SQL Objects, and transaction callbacks.

Limitations: SQL strings have limited compile-time validation, and the application owns joins, loading strategies, and relationship assembly.

Common uses: services with explicit SQL, modest data models, and teams that want a small abstraction over JDBC.

MyBatis

Advantages: maps explicit SQL to Java methods and objects, with flexible XML or annotation-based configuration and detailed result mapping.

Limitations: mapper definitions add another artifact to maintain, and SQL changes can drift from mappings without integration tests.

Common uses: SQL-led applications, existing schemas, stored procedures, and teams that prefer mapper interfaces.

jOOQ

Advantages: models SQL as a composable Java DSL. Optional schema code generation gives compiler-visible tables, columns, and types, while jOOQ can also be used without generated code.

Limitations: the DSL and generation workflow have a learning and build cost. The Open Source Edition is Apache 2.0, including its runtime and code generator, but supports a defined set of databases. Other databases and advanced features require an appropriate commercial edition.

Common uses: applications with sophisticated SQL, dynamic query construction, database-first schemas, or a strong preference for typed query composition. Check the current edition matrix and licensing terms for the target database.

Object-relational mapping

JPA

Advantages: standard entity, relationship, query, and lifecycle APIs that allow a degree of provider portability.

Limitations: it is a specification rather than a complete runtime. Applications still need a provider and must understand fetching, transactions, generated SQL, and provider-specific behavior.

Common uses: domain-oriented applications that value standard persistence contracts and managed entity lifecycles.

Hibernate

Advantages: a mature JPA implementation with extensive mapping options, relationship management, dirty checking, caching, HQL, and a large ecosystem.

Limitations: the persistence context, proxies, fetching, cascading, flushing, and dirty checking create runtime behavior that developers must understand and observe.

Common uses: applications with substantial object graphs, relationship-heavy domain models, and teams that benefit from managed entity state.

EclipseLink

Advantages: a complete JPA implementation with its own mapping, caching, query, and extensibility features.

Limitations: provider differences still matter, and fewer teams and integrations default to EclipseLink than to Hibernate.

Common uses: Jakarta EE environments, Eclipse-centered stacks, and projects that prefer EclipseLink-specific capabilities.

Framework-integrated persistence

Spring also offers Spring Data JDBC, which maps aggregates through JDBC without requiring JPA. It has not been included in the experiments collected here.

Spring JDBC

Advantages: JdbcTemplate and related APIs handle repetitive JDBC resource work while integrating with Spring transactions and exception translation.

Limitations: SQL, mappings, query composition, and relationship loading remain explicit.

Common uses: Spring applications that want SQL control without an ORM.

Spring Data JPA

Advantages: repository interfaces, derived queries, specifications, pagination, auditing, and Spring transaction integration over JPA.

Limitations: repository convenience sits on top of the ORM model. Fetching, entity state, flush behavior, and generated SQL still need attention.

Common uses: Spring applications whose domain model benefits from JPA and whose teams value repository conventions.

Micronaut Data JDBC

Advantages: generates repository implementations and query metadata at compile time while executing through JDBC.

Limitations: it follows Micronaut Data's mapping and repository model, without JPA entity management or dirty checking.

Common uses: Micronaut applications that want repositories, direct JDBC behavior, and compile-time generation.

Micronaut Data JPA

Advantages: combines compile-time generated repositories with a JPA provider and ORM capabilities.

Limitations: compile-time repository generation does not remove provider runtime behavior or ORM loading decisions.

Common uses: Micronaut applications that need JPA mappings and relationships with generated repository infrastructure.

PVR Labs Java persistence experiments

These experiments measure complete applications under stated workloads. Process RSS includes the JVM, application code, persistence implementation, drivers, embedded databases where used, and instrumentation. It is not an intrinsic memory measurement of a library.

Focused persistence comparisons

Spring Boot JPA vs JDBC

Two complete Spring Boot variants on one Mac. The Spring JDBC application used about 90 to 91 MiB less median RSS and reached its first dashboard roughly four seconds sooner than the Spring Data JPA and Hibernate variant.

JPA Memory Experiment Revisited

A follow-up on a 512 MiB Linux VM using substantially shared lightweight application code. Jdbi used about 55 to 58 MiB less process RSS than direct Hibernate in the measured mixed workload. The result compares implementations, not isolated libraries.

Jdbi, MyBatis, and jOOQ on 512 MiB

Two runs per SQL-centric implementation with Javalin, H2, and no swap. MyBatis had the lowest median workload RSS in both rounds, while Jdbi was competitive on latency. The narrow workload does not establish a universal ranking.

MyBatis, jOOQ, and Jdbi on 256 MiB

The earlier one-run comparison recorded startup, RSS, paging, package size, and HTTP latency under tighter memory. Swap activity complicates cross-library RSS interpretation, which motivated the 512 MiB follow-up.

Broader application-stack comparisons

These studies change the web framework, application infrastructure, or overall implementation as well as persistence. Their results cannot be assigned to the persistence library alone.

Rewriting Spring PetClinic with CoilBase

A rewrite preserving key PetClinic workflows, covering application RSS, deployment size, readiness, request timing, and the integration work required when replacing a Spring Boot and Hibernate stack.

Spring Boot vs Javalin and Jdbi

A database-backed service on a 512 MiB VM, comparing complete Spring Boot and Javalin stacks on HotSpot and Native Image. HTTP, persistence, logging, JSON, metrics, and other components all differ.