An object-relational mapper (ORM) persists application objects in relational database tables and recreates them when needed. Mapping metadata describes how classes and properties correspond to the SQL schema; the ORM performs the transformation between objects in memory and stored data. This replaces much repetitive work, such as copying JDBC results into objects and writing SQL for common persistence operations. It does not remove the need to understand relational modeling or SQL. section 1.3 section 1.4
The central difficulty is the object-relational mismatch. An object network cannot simply be stored as one table row: its state must be represented in columns and relationships. Inheritance adds another problem. An object may refer to any subclass of a billing-details type, but a relational foreign key refers to one target table. Mapping choices must preserve the behavior the application needs while fitting the database structure. section 1.4 section 1.2.2
In a Java application, the main layers have distinct jobs:
- JPA defines the standard persistence and mapping API; Hibernate implements it and also offers a native API. section 1.3 section 2.1
- Spring Data JPA sits above a JPA provider and reduces data-access boilerplate, including through queries generated from method names. The same JPA-annotated class mappings can serve Hibernate and Spring Data JPA. section 1.3 section 5.0
- Spring Data JDBC offers a simpler, more limited ORM. It uses SQL rather than JPQL and has no lazy loading, caching, sessions, or dirty tracking; entities must be saved explicitly. section 15.0
Mapping an auction domain
An auction application may persist users, items, bids, categories, and billing details. A user can have multiple billing details, while billing strategies can be subclasses of a common type. Basic properties of a persistent class are mapped by default when their types are recognized; JPA annotations customize exceptional cases. Collections, parent-child relationships, and associations require closer attention because object references must correspond to relationships between tables. section 3.1.3 section 6.1 section 8.0
SELECT * FROM USERS, BILLINGDETAILS WHERE USERS.ID = 123 AND BILLINGDETAILS.ID = USERS.ID
This SQL query retrieves a user together with billing details. An ORM still has to account for the same retrieval choice: loading associated data requires database work, even when Java code accesses it by navigating objects. section 1.2.5
Choose retrieval strategies with the intended object navigation in mind. Too many database requests hurt performance, but fetching an unnecessarily large network wastes memory and can produce large query results. Inspect the SQL emitted by an ORM and its performance implications rather than treating mapping as a substitute for query design. section 1.2.5 section 1.3






